#tag Module
Protected Module Module1
	#tag Method, Flags = &h0
		Function build_new_filename() As string
		  dim newfilename as string = MainWindow.ShowOrMovieName_TextField.text
		  
		  if  instr(MainWindow.MediaType_TextField.Text, "TV Show" ) <> 0 then
		    dim season as string = MainWindow.Season_PopupMenu.text
		    dim episode as string = MainWindow.EpisodeNumber_PopupMenu.text
		    dim episodetype as string = MainWindow.ShowOrMovieType_PopupMenu.text
		    dim episode_key as string = "E"
		    if instr(episodetype, "Commentary") <> 0 then
		      episode_key = "C"
		    else
		      if instr(episodetype, "Special") <> 0 then
		        episode_key = "S"
		      end if
		    end if
		    newfilename = newfilename + " - S" + season + episode_key + episode + " - " + MainWindow.episodeTitle_TextField.text
		    
		  else
		    
		    //do IMDB
		    newfilename = newfilename + " - tt" + MainWindow.IMDB_TextField.text
		    
		    // do year
		    newfilename = newfilename + " - " + MainWindow.Year_TextField.text
		    
		    // do screen rating
		    dim sr as string = ""
		    if MainWindow.sr_s_CheckBox.value then sr = sr + "S"
		    if MainWindow.sr_l_CheckBox.value then sr = sr + "L"
		    if MainWindow.sr_fv_CheckBox.value then sr = sr + "FV"
		    if MainWindow.sr_v_CheckBox.value then sr = sr + "V"
		    if MainWindow.sr_d_CheckBox.value then sr = sr + "D"
		    newfilename = newfilename + "~" + sr
		    
		    // do tv rating
		    dim tvr as string = ""
		    if MainWindow.tvr_RadioButton(0).value then tvr = "Y7"
		    if MainWindow.tvr_RadioButton(1).value then tvr = "Y"
		    if MainWindow.tvr_RadioButton(2).value then tvr = "G"
		    if MainWindow.tvr_RadioButton(3).value then tvr = "14"
		    if MainWindow.tvr_RadioButton(4).value then tvr = "PG"
		    if MainWindow.tvr_RadioButton(5).value then tvr = "MA"
		    if MainWindow.tvr_RadioButton(6).value then tvr = "NR"
		    if MainWindow.tvr_RadioButton(7).value then tvr = "NoR"
		    newfilename = newfilename + "-" + tvr
		    
		    // do mpaa rating
		    dim mpaa as string = ""
		    if MainWindow.mpaar_RadioButton(0).value then mpaa = "G"
		    if MainWindow.mpaar_RadioButton(1).value then mpaa = "PG"
		    if MainWindow.mpaar_RadioButton(2).value then mpaa = "13"
		    if MainWindow.mpaar_RadioButton(3).value then mpaa = "17"
		    if MainWindow.mpaar_RadioButton(4).value then mpaa = "R"
		    if MainWindow.mpaar_RadioButton(5).value then mpaa = "X"
		    if MainWindow.mpaar_RadioButton(6).value then mpaa = "NR"
		    if MainWindow.mpaar_RadioButton(7).value then mpaa = "NoR"
		    newfilename = newfilename + "-" + mpaa
		    
		  end if
		  
		  
		  // do extension
		  dim extension as string = ""
		  Dim myRegEx_EXTENSION As new RegEx
		  Dim myMatch_EXTENSION As new RegExMatch
		  myRegEx_EXTENSION.SearchPattern="\.(...)$"
		  myMatch_EXTENSION=myRegEx_EXTENSION.search(MainWindow.ActualFilename_StaticText.text)
		  if  myMatch_EXTENSION <> Nil then
		    extension = myMatch_EXTENSION.SubExpressionString(1)
		  end if
		  
		  // dim extension as string = right(MainWindow.ActualFilename_StaticText.text,3)
		  
		  newfilename = newfilename + "." + Extension
		  
		  return newfilename
		End Function
	#tag EndMethod

	#tag Method, Flags = &h0
		Function build_plist_for(which_list as string, which_list_contents as string, separatedby as string) As string
		  Dim myRegEx As new RegEx
		  myRegEx.SearchPattern = "[\n\r\f]"
		  myRegEx.ReplacementPattern = " "
		  
		  dim _plist as string = "<key>" + which_list + "</key>"
		  dim i as integer
		  dim _plist_part as string = ""
		  dim last as integer =CountFields(which_list_contents,separatedby)
		  
		  if last > 0 then
		    For i=1 to last
		      dim contents as string = myRegEx.Replace(NthField(which_list_contents,separatedby,i))
		      if contents.len > 0 then
		        _plist_part = _plist_part + "<dict><key>name</key><string>" + contents + "</string></dict>"
		      end if
		    next
		  else
		    if which_list_contents.len > 0 then
		      _plist_part = _plist_part + "<dict><key>name</key><string>" + which_list_contents + "</string></dict>"
		    end if
		  end if
		  
		  if instr(_plist_part,"<dict>") <> 0 then
		    _plist = _plist + "<array>" + _plist_part + "</array>"
		  else
		    _plist = _plist + "<array/>"
		  end if
		  
		  return _plist
		End Function
	#tag EndMethod

	#tag Method, Flags = &h0
		Function build_pytivo_list_for(which_list as string, which_list_contents as string, separatedby as string) As string
		  Dim myRegEx As new RegEx
		  myRegEx.SearchPattern = "[\n\r\f]"
		  myRegEx.ReplacementPattern = " "
		  
		  dim _plist as string
		  dim i as integer
		  
		  
		  dim last as integer =CountFields(which_list_contents,separatedby)
		  if last > 0 then
		    For i=1 to last
		      dim contents as string = myRegEx.Replace(NthField(which_list_contents,separatedby,i))
		      if contents.len > 0 then
		        _plist = _plist + which_list + " : " + contents + EndOfLine
		      end if
		    next
		  else
		    if which_list_contents.len > 0 then
		      _plist = _plist + which_list + " : " + which_list_contents + EndOfLine
		    end if
		  end if
		  
		  return _plist
		End Function
	#tag EndMethod

	#tag Method, Flags = &h0
		Function check_for_movie_or_tvshow_format(filename as string, path as string) As dictionary
		  dim _dict as new dictionary
		  
		  if not _dict.haskey("valid")  then
		    Dim myRegEx_TV As new RegEx
		    Dim myMatch_TV As new RegExMatch
		    
		    Dim myRegEx_MOVIE As new RegEx
		    Dim myMatch_MOVIE As new RegExMatch
		    
		    Dim myRegEx_FNMATCH As new RegEx
		    Dim myMatch_FNMATCH As new RegExMatch
		    
		    myRegEx_MOVIE.SearchPattern="^(.*?)\s-\s(.*?tt)([\d]{1,9})\s-\s([\d]{4})\~(.*?)\-(.*?)\-(.*?)\....$"
		    myMatch_MOVIE=myRegEx_MOVIE.search(filename)
		    if  myMatch_MOVIE <> Nil then
		      _dict.value("valid") = 1
		      _dict.value("type") = "M"
		      _dict.value("movie_name") = myMatch_MOVIE.SubExpressionString(1)
		      
		      _dict.value("file_type") = "Unknown"
		      if myMatch_MOVIE.SubExpressionString(2) = "tt" then
		        _dict.value("file_type") = "Movie"
		      else
		        if myMatch_MOVIE.SubExpressionString(2) = "Ctt" then
		          _dict.value("file_type") = "Commentary"
		        else
		          if myMatch_MOVIE.SubExpressionString(2) = "Stt" then
		            _dict.value("file_type") = "Special"
		          end if
		        end if
		      end if
		      
		      _dict.value("imdb_number") = myMatch_MOVIE.SubExpressionString(3)
		      _dict.value("movie_year") = myMatch_MOVIE.SubExpressionString(4)
		      // MsgBox("Parsed movie filename: IMDB#: tt" + _dict.value("imdb_number") )
		      
		      dim svldfv_rating as string = ReplaceB(myMatch_MOVIE.SubExpressionString(5),"FV","F")
		      _dict.value("svldfv_rating") = svldfv_rating
		      
		      _dict.value("tv_rating") = myMatch_MOVIE.SubExpressionString(6)
		      _dict.value("movie_rating") = myMatch_MOVIE.SubExpressionString(7)
		      
		    else
		      
		      myRegEx_TV.SearchPattern="^(.*?)\s-\sS([\d]{2})([A-Z])([\d]{2})\s-\s(.*?)\.(...)$"
		      myMatch_TV=myRegEx_TV.search(filename)
		      if  myMatch_TV <> Nil then
		        _dict.value("valid") = 1
		        _dict.value("type") = "T"
		        _dict.value("show_name") = myMatch_TV.SubExpressionString(1)
		        _dict.value("season") =  myMatch_TV.SubExpressionString(2)
		        _dict.value("extension") =  myMatch_TV.SubExpressionString(6)
		        
		        _dict.value("file_type") = "Unknown"
		        if myMatch_TV.SubExpressionString(3) = "S" then
		          _dict.value("file_type") = "Special"
		        else
		          if myMatch_TV.SubExpressionString(3) = "C" then
		            _dict.value("file_type") = "Commentary"
		          else
		            if myMatch_TV.SubExpressionString(3) = "E" then
		              _dict.value("file_type") = "Episode"
		            end if
		          end if
		        end if
		        _dict.value("episode") =  myMatch_TV.SubExpressionString(4)
		        _dict.value("episode_title") = myMatch_TV.SubExpressionString(5)
		        // MsgBox("SEASON: '" + myMatch_TV.SubExpressionString(2) + "'/EPISODE: '" + myMatch_TV.SubExpressionString(4) + "'")
		        
		      else
		        myRegEx_TV.SearchPattern="^(.*?)\s([\d]{3,4})\s(.*?)\.(...)$"
		        myMatch_TV=myRegEx_TV.search(filename)
		        if  myMatch_TV <> Nil then
		          _dict.value("valid") = 1
		          _dict.value("type") = "T"
		          _dict.value("show_name") = myMatch_TV.SubExpressionString(1)
		          _dict.value("episode_title") = myMatch_TV.SubExpressionString(3)
		          _dict.value("extension") =  myMatch_TV.SubExpressionString(4)
		          _dict.value("file_type") = "Episode"
		          
		          dim season_episode() as string
		          season_episode() = parse_season_episode_from_number(myMatch_TV.SubExpressionString(2))
		          _dict.value("season") = season_episode(0)
		          _dict.value("episode") = season_episode(1)
		          
		        else
		          
		          myRegEx_TV.SearchPattern="^(.*?)\s([\d]{3,4})\.(...)$"
		          myMatch_TV=myRegEx_TV.search(filename)
		          if  myMatch_TV <> Nil then
		            _dict.value("valid") = 1
		            _dict.value("type") = "T"
		            _dict.value("show_name") = myMatch_TV.SubExpressionString(1)
		            _dict.value("episode_title") = ""
		            _dict.value("extension") =  myMatch_TV.SubExpressionString(3)
		            _dict.value("file_type") = "Episode"
		            
		            dim season_episode() as string
		            season_episode() = parse_season_episode_from_number(myMatch_TV.SubExpressionString(2))
		            _dict.value("season") = season_episode(0)
		            _dict.value("episode") = season_episode(1)
		            
		          else
		            myRegEx_TV.SearchPattern="^(.*?)\WS([\d]{1,2})E([\d]{1,2})\.(...)$"
		            myMatch_TV=myRegEx_TV.search(filename)
		            if  myMatch_TV <> Nil then
		              _dict.value("valid") = 1
		              _dict.value("type") = "T"
		              _dict.value("show_name") = ReplaceAll(myMatch_TV.SubExpressionString(1),"."," ")
		              _dict.value("episode_title") = ""
		              _dict.value("season") =  myMatch_TV.SubExpressionString(2)
		              _dict.value("episode") =  myMatch_TV.SubExpressionString(3)
		              _dict.value("file_type") = "Episode"
		              _dict.value("extension") =  myMatch_TV.SubExpressionString(4)
		              
		            else
		              myRegEx_TV.SearchPattern="^(.*?).(...)$"
		              myMatch_TV=myRegEx_TV.search(filename)
		              if  myMatch_TV <> Nil then
		                _dict.value("type") = "T"
		                // _dict.value("show_name") = myMatch_TV.SubExpressionString(1)
		                _dict.value("episode_title") = ""
		                _dict.value("extension") =  myMatch_TV.SubExpressionString(2)
		                #if TargetMacOS
		                  myRegEx_FNMATCH.SearchPattern="^.*\:(.+?)\:Series\s+([\d]+)\:$"
		                  myMatch_FNMATCH=myRegEx_FNMATCH.search(path)
		                  if  myMatch_FNMATCH <> Nil then
		                    _dict.value("valid") = 1
		                    _dict.value("file_type") = "Episode"
		                    _dict.value("show_name") = myMatch_FNMATCH.SubExpressionString(1)
		                    // MsgBox("(Series) " + path + endofline + "Show Name: '" + myMatch_FNMATCH.SubExpressionString(1) + "'" )
		                    _dict.value("season") =  myMatch_FNMATCH.SubExpressionString(2)
		                    // MsgBox("(Series) Season: '" +myMatch_FNMATCH.SubExpressionString(2) + "'" )
		                  else
		                    myRegEx_FNMATCH.SearchPattern="^.*\:(.+?)\:Season\s+([\d]+)\:$"
		                    myMatch_FNMATCH=myRegEx_FNMATCH.search(path)
		                    if  myMatch_FNMATCH <> Nil then
		                      _dict.value("valid") = 1
		                      _dict.value("file_type") = "Episode"
		                      _dict.value("show_name") = myMatch_FNMATCH.SubExpressionString(1)
		                      // MsgBox("(Series) " + path + endofline + "Show Name: '" + myMatch_FNMATCH.SubExpressionString(1) + "'" )
		                      _dict.value("season") =  myMatch_FNMATCH.SubExpressionString(2)
		                      // MsgBox("(Series) Season: '" +myMatch_FNMATCH.SubExpressionString(2) + "'" )
		                    end if
		                  end if
		                #else
		                  #if TargetWin32
		                    myRegEx_FNMATCH.SearchPattern="\\(.*?)\\(Season|Series)\s+([\d]+)\\$"
		                    myMatch_FNMATCH=myRegEx_FNMATCH.search(path)
		                    if  myMatch_FNMATCH <> Nil then
		                      _dict.value("valid") = 1
		                      _dict.value("file_type") = "Episode"
		                      _dict.value("show_name") = myMatch_FNMATCH.SubExpressionString(1)
		                      _dict.value("season") =  myMatch_FNMATCH.SubExpressionString(3)
		                    end if
		                  #endif
		                #endif
		              end if
		            end if
		          end if
		          
		        end if
		      end if
		    end if
		  end if
		  
		  
		  return _dict
		  
		End Function
	#tag EndMethod

	#tag Method, Flags = &h0
		Sub compute_new_filename()
		  dim _status_dict as new dictionary
		  MainWindow.RenameFile_BevelButton.Enabled = false
		  
		  _status_dict = validate_newfilename_options()
		  
		  if _status_dict.HasKey("status") then
		    if _status_dict.value("status") = "-1" then
		      if MainWindow.ActualFilename_StaticText.text.Len > 0 then MsgBox("Status: " + _status_dict.value("status")  + " Reason: " + _status_dict.value("reason"))
		      MainWindow.NewFilename_StaticText.Text = ""
		      if MainWindow.NewFilenameLabel_StaticText.Enabled <> false then MainWindow.NewFilenameLabel_StaticText.Enabled = false
		      if MainWindow.NewFilename_StaticText.Enabled <> false then MainWindow.NewFilename_StaticText.Enabled = false
		    else
		      dim newfilename as string = build_new_filename()
		      if MainWindow.NewFilenameLabel_StaticText.Enabled <> true then MainWindow.NewFilenameLabel_StaticText.Enabled = true
		      if MainWindow.NewFilename_StaticText.Enabled <> true then MainWindow.NewFilename_StaticText.Enabled = true
		      MainWindow.NewFilename_StaticText.Text = newfilename
		      MainWindow.NewFilename_StaticText.Refresh
		      if MainWindow.ActualFilename_StaticText.Text <> MainWindow.NewFilename_StaticText.Text then
		        if MainWindow.ActualFilename_StaticText.text.Len > 4 then MainWindow.RenameFile_BevelButton.Enabled = true
		      end if
		    end if
		    
		  else
		    MsgBox("Could not compute new filename.  Status was not returned from function validate_newfilename_options()")
		  end if
		  
		  
		End Sub
	#tag EndMethod

	#tag Method, Flags = &h0
		Sub defaults_for_rating_misc_page_load()
		  _d_ratings_misc_for_show.value("loading") = 1
		  if _d_ratings_misc_for_show.haskey("loaded") then
		    if _d_ratings_misc_for_show.value("loaded") = 1 then
		      
		      // MsgBox("Loaded: " + _d_ratings_misc_for_show.value("loaded"))
		      
		      if _d_ratings_misc_for_show.HasKey("ratingsmisc_colorCode_RadioButton") then
		        MainWindow.ratingsmisc_colorCode_RadioButton(_d_ratings_misc_for_show.value("ratingsmisc_colorCode_RadioButton")).value = true
		      end if
		      
		      if _d_ratings_misc_for_show.HasKey("ratingsmisc_s_CheckBox") then
		        MainWindow.ratingsmisc_s_CheckBox.value = true
		      end if
		      if _d_ratings_misc_for_show.HasKey("ratingsmisc_l_CheckBox") then
		        MainWindow.ratingsmisc_l_CheckBox.value = true
		      end if
		      if _d_ratings_misc_for_show.HasKey("ratingsmisc_fv_CheckBox") then
		        MainWindow.ratingsmisc_fv_CheckBox.value = true
		      end if
		      if _d_ratings_misc_for_show.HasKey("ratingsmisc_v_CheckBox") then
		        MainWindow.ratingsmisc_v_CheckBox.value = true
		      end if
		      if _d_ratings_misc_for_show.HasKey("ratingsmisc_d_CheckBox") then
		        MainWindow.ratingsmisc_d_CheckBox.value = true
		      end if
		      
		      if _d_ratings_misc_for_show.HasKey("ratingsmisc_tvr_RadioButton") then
		        MainWindow.ratingsmisc_tvr_RadioButton(_d_ratings_misc_for_show.value("ratingsmisc_tvr_RadioButton")).value = true
		      end if
		      
		      if _d_ratings_misc_for_show.HasKey("ratingsmisc_mpaar_RadioButton") then
		        MainWindow.ratingsmisc_mpaar_RadioButton(_d_ratings_misc_for_show.value("ratingsmisc_mpaar_RadioButton")).value = true
		      end if
		      
		      if _d_ratings_misc_for_show.HasKey("ratingsmisc_cc_CheckBox") then
		        MainWindow.ratingsmisc_cc_CheckBox.value = true
		      end if
		      if _d_ratings_misc_for_show.HasKey("ratingsmisc_stereo_CheckBox") then
		        MainWindow.ratingsmisc_stereo_CheckBox.value = true
		      end if
		      if _d_ratings_misc_for_show.HasKey("ratingsmisc_sap_CheckBox") then
		        MainWindow.ratingsmisc_sap_CheckBox.value = true
		      end if
		      if _d_ratings_misc_for_show.HasKey("ratingsmisc_sub_Checkbox") then
		        MainWindow.ratingsmisc_sub_Checkbox.value = true
		      end if
		      if _d_ratings_misc_for_show.HasKey("ratingsmisc_repeat_CheckBox") then
		        MainWindow.ratingsmisc_repeat_CheckBox.value = true
		      end if
		      if _d_ratings_misc_for_show.HasKey("ratingsmisc_hd_Checkbox") then
		        MainWindow.ratingsmisc_hd_Checkbox.value = true
		      end if
		      if _d_ratings_misc_for_show.HasKey("ratingsmisc_letterbox_CheckBox") then
		        MainWindow.ratingsmisc_letterbox_CheckBox.value = true
		      end if
		      
		    end if
		  end if
		  if _d_ratings_misc_for_show.haskey("loading") then
		    _d_ratings_misc_for_show.remove("loading")
		  end if
		End Sub
	#tag EndMethod

	#tag Method, Flags = &h0
		Sub defaults_for_rating_misc_page_save()
		  if _d_prefs.haskey("pref_ratingsmisc_RatingsForShowMovie_PopupMenu") then
		    if _d_prefs.value("pref_ratingsmisc_RatingsForShowMovie_PopupMenu") <> 1 then
		      if not _d_ratings_misc_for_show.haskey("loading") then
		        if ( (MainWindow.TVSeriesId_TextField.Text.Len > 0) or (MainWindow.IMDB_TextField.Text.Len > 0) ) then
		          if _d_prefs.value("pref_ratingsmisc_RatingsForShowMovie_PopupMenu") = 0 then
		            dim i as integer
		            
		            for i = 0 to 3
		              _d_ratings_misc_for_show = dict_key_set_or_clear(_d_ratings_misc_for_show,"ratingsmisc_colorCode_RadioButton",0,"clear")
		            next
		            for i = 0 to 3
		              if MainWindow.ratingsmisc_colorCode_RadioButton(i).value  then
		                _d_ratings_misc_for_show = dict_key_set_or_clear(_d_ratings_misc_for_show,"ratingsmisc_colorCode_RadioButton",i,"set")
		              end if
		            next
		            
		            
		            if MainWindow.ratingsmisc_s_CheckBox.value then
		              _d_ratings_misc_for_show = dict_key_set_or_clear(_d_ratings_misc_for_show,"ratingsmisc_s_CheckBox",1,"set")
		            else
		              _d_ratings_misc_for_show = dict_key_set_or_clear(_d_ratings_misc_for_show,"ratingsmisc_s_CheckBox",1,"clear")
		            end if
		            
		            if MainWindow.ratingsmisc_l_CheckBox.value then
		              _d_ratings_misc_for_show = dict_key_set_or_clear(_d_ratings_misc_for_show,"ratingsmisc_l_CheckBox",1,"set")
		            else
		              _d_ratings_misc_for_show = dict_key_set_or_clear(_d_ratings_misc_for_show,"ratingsmisc_l_CheckBox",1,"clear")
		            end if
		            
		            if MainWindow.ratingsmisc_fv_CheckBox.value then
		              _d_ratings_misc_for_show = dict_key_set_or_clear(_d_ratings_misc_for_show,"ratingsmisc_fv_CheckBox",1,"set")
		            else
		              _d_ratings_misc_for_show = dict_key_set_or_clear(_d_ratings_misc_for_show,"ratingsmisc_fv_CheckBox",1,"clear")
		            end if
		            
		            if MainWindow.ratingsmisc_v_CheckBox.value then
		              _d_ratings_misc_for_show = dict_key_set_or_clear(_d_ratings_misc_for_show,"ratingsmisc_v_CheckBox",1,"set")
		            else
		              _d_ratings_misc_for_show = dict_key_set_or_clear(_d_ratings_misc_for_show,"ratingsmisc_v_CheckBox",1,"clear")
		            end if
		            
		            if MainWindow.ratingsmisc_d_CheckBox.value then
		              _d_ratings_misc_for_show = dict_key_set_or_clear(_d_ratings_misc_for_show,"ratingsmisc_d_CheckBox",1,"set")
		            else
		              _d_ratings_misc_for_show = dict_key_set_or_clear(_d_ratings_misc_for_show,"ratingsmisc_d_CheckBox",1,"clear")
		            end if
		            
		            for i = 0 to 7
		              _d_ratings_misc_for_show = dict_key_set_or_clear(_d_ratings_misc_for_show,"ratingsmisc_tvr_RadioButton",0,"clear")
		            next
		            for i = 0 to 7
		              if MainWindow.ratingsmisc_tvr_RadioButton(i).value then
		                _d_ratings_misc_for_show = dict_key_set_or_clear(_d_ratings_misc_for_show,"ratingsmisc_tvr_RadioButton",i,"set")
		              end if
		            next
		            
		            for i = 0 to 7
		              _d_ratings_misc_for_show = dict_key_set_or_clear(_d_ratings_misc_for_show,"ratingsmisc_mpaar_RadioButton",0,"clear")
		            next
		            for i = 0 to 7
		              if MainWindow.ratingsmisc_mpaar_RadioButton(i).value then
		                _d_ratings_misc_for_show = dict_key_set_or_clear(_d_ratings_misc_for_show,"ratingsmisc_mpaar_RadioButton",i,"set")
		              end if
		            next
		            
		            
		            if MainWindow.ratingsmisc_cc_CheckBox.value then
		              _d_ratings_misc_for_show = dict_key_set_or_clear(_d_ratings_misc_for_show,"ratingsmisc_cc_CheckBox",1,"set")
		            else
		              _d_ratings_misc_for_show = dict_key_set_or_clear(_d_ratings_misc_for_show,"ratingsmisc_cc_CheckBox",1,"clear")
		            end if
		            
		            if MainWindow.ratingsmisc_stereo_CheckBox.value then
		              _d_ratings_misc_for_show = dict_key_set_or_clear(_d_ratings_misc_for_show,"ratingsmisc_stereo_CheckBox",1,"set")
		            else
		              _d_ratings_misc_for_show = dict_key_set_or_clear(_d_ratings_misc_for_show,"ratingsmisc_stereo_CheckBox",1,"clear")
		            end if
		            
		            if MainWindow.ratingsmisc_sap_CheckBox.value then
		              _d_ratings_misc_for_show = dict_key_set_or_clear(_d_ratings_misc_for_show,"ratingsmisc_sap_CheckBox",1,"set")
		            else
		              _d_ratings_misc_for_show = dict_key_set_or_clear(_d_ratings_misc_for_show,"ratingsmisc_sap_CheckBox",1,"clear")
		            end if
		            
		            if MainWindow.ratingsmisc_sub_Checkbox.value then
		              _d_ratings_misc_for_show = dict_key_set_or_clear(_d_ratings_misc_for_show,"ratingsmisc_sub_Checkbox",1,"set")
		            else
		              _d_ratings_misc_for_show = dict_key_set_or_clear(_d_ratings_misc_for_show,"ratingsmisc_sub_Checkbox",1,"clear")
		            end if
		            
		            if MainWindow.ratingsmisc_repeat_CheckBox.value then
		              _d_ratings_misc_for_show = dict_key_set_or_clear(_d_ratings_misc_for_show,"ratingsmisc_repeat_CheckBox",1,"set")
		            else
		              _d_ratings_misc_for_show = dict_key_set_or_clear(_d_ratings_misc_for_show,"ratingsmisc_repeat_CheckBox",1,"clear")
		            end if
		            
		            if MainWindow.ratingsmisc_hd_Checkbox.value then
		              _d_ratings_misc_for_show = dict_key_set_or_clear(_d_ratings_misc_for_show,"ratingsmisc_hd_Checkbox",1,"set")
		            else
		              _d_ratings_misc_for_show = dict_key_set_or_clear(_d_ratings_misc_for_show,"ratingsmisc_hd_Checkbox",1,"clear")
		            end if
		            
		            if MainWindow.ratingsmisc_letterbox_CheckBox.value then
		              _d_ratings_misc_for_show = dict_key_set_or_clear(_d_ratings_misc_for_show,"ratingsmisc_letterbox_CheckBox",1,"set")
		            else
		              _d_ratings_misc_for_show = dict_key_set_or_clear(_d_ratings_misc_for_show,"ratingsmisc_letterbox_CheckBox",1,"clear")
		            end if
		            
		          end if
		          
		          dim appdataf as folderitem = GetFolderItem(SpecialFolder.ApplicationData.AbsolutePath + "Tago")
		          dim _seriesratingsmiscdatafile as folderitem
		          
		          if MainWindow.TVSeriesId_TextField.Text.Len > 0 then
		            _seriesratingsmiscdatafile =  GetFolderItem(appdataf.AbsolutePath + "TVDB-" + strtohex(MainWindow.TVSeriesId_TextField.text) )
		          else
		            if MainWindow.IMDB_TextField.Text.Len > 0 then
		              _seriesratingsmiscdatafile =  GetFolderItem(appdataf.AbsolutePath + "IMDB-" + strtohex(MainWindow.IMDB_TextField.text) )
		            end if
		          end if
		          
		          dim loaded as Boolean = _d_ratings_misc_for_show.SaveXML(_seriesratingsmiscdatafile,true)
		          
		        end if
		      end if
		    end if
		  end if
		  
		End Sub
	#tag EndMethod

	#tag Method, Flags = &h0
		Function dict_key_set_or_clear(_dict as Dictionary, keyname as string, set_to as integer, set_or_clear as string) As Dictionary
		  if  _dict.haskey("loaded") then
		    _dict.remove("loaded")
		  end if
		  
		  if set_or_clear = "set" then
		    _dict.value(keyname) = set_to
		  else
		    if set_or_clear = "clear" then
		      if _dict.HasKey(keyname) then
		        _dict.remove(keyname)
		      end if
		    end if
		  end if
		  
		  dim keys() as Variant = _dict.Keys
		  
		  if ubound(keys) > 0 then
		    _dict.value("loaded") = 1
		  else
		    _dict.value("loaded") = 0
		  end if
		  
		  return _dict
		End Function
	#tag EndMethod

	#tag Method, Flags = &h0
		Sub enable_checkboxes_radiobuttons_on_fileinformation()
		  MainWindow.sr_s_CheckBox.Enabled = true
		  MainWindow.sr_v_CheckBox.Enabled = true
		  MainWindow.sr_l_CheckBox.Enabled = true
		  MainWindow.sr_d_CheckBox.Enabled = true
		  MainWindow.sr_fv_CheckBox.Enabled = true
		  
		  MainWindow.tvr_RadioButton(0).Enabled = true
		  MainWindow.tvr_RadioButton(1).Enabled = true
		  MainWindow.tvr_RadioButton(2).Enabled = true
		  MainWindow.tvr_RadioButton(3).Enabled = true
		  MainWindow.tvr_RadioButton(4).Enabled = true
		  MainWindow.tvr_RadioButton(5).Enabled = true
		  MainWindow.tvr_RadioButton(6).Enabled = true
		  MainWindow.tvr_RadioButton(7).Enabled = true
		  
		  MainWindow.mpaar_RadioButton(0).Enabled = true
		  MainWindow.mpaar_RadioButton(1).Enabled = true
		  MainWindow.mpaar_RadioButton(2).Enabled = true
		  MainWindow.mpaar_RadioButton(3).Enabled = true
		  MainWindow.mpaar_RadioButton(4).Enabled = true
		  MainWindow.mpaar_RadioButton(5).Enabled = true
		  MainWindow.mpaar_RadioButton(6).Enabled = true
		  MainWindow.mpaar_RadioButton(7).Enabled = true
		  
		End Sub
	#tag EndMethod

	#tag Method, Flags = &h0
		Sub enable_checkboxes_radiobuttons_on_ratingsmisc()
		  MainWindow.ratingsmisc_colorCode_RadioButton(0).Enabled = true
		  MainWindow.ratingsmisc_colorCode_RadioButton(1).Enabled = true
		  MainWindow.ratingsmisc_colorCode_RadioButton(2).Enabled = true
		  MainWindow.ratingsmisc_colorCode_RadioButton(3).Enabled = true
		  
		  MainWindow.ratingsmisc_s_CheckBox.Enabled = true
		  MainWindow.ratingsmisc_v_CheckBox.Enabled = true
		  MainWindow.ratingsmisc_l_CheckBox.Enabled = true
		  MainWindow.ratingsmisc_d_CheckBox.Enabled = true
		  MainWindow.ratingsmisc_fv_CheckBox.Enabled = true
		  
		  MainWindow.ratingsmisc_tvr_RadioButton(0).Enabled = true
		  MainWindow.ratingsmisc_tvr_RadioButton(1).Enabled = true
		  MainWindow.ratingsmisc_tvr_RadioButton(2).Enabled = true
		  MainWindow.ratingsmisc_tvr_RadioButton(3).Enabled = true
		  MainWindow.ratingsmisc_tvr_RadioButton(4).Enabled = true
		  MainWindow.ratingsmisc_tvr_RadioButton(5).Enabled = true
		  MainWindow.ratingsmisc_tvr_RadioButton(6).Enabled = true
		  MainWindow.ratingsmisc_tvr_RadioButton(7).Enabled = true
		  
		  MainWindow.ratingsmisc_mpaar_RadioButton(0).Enabled = true
		  MainWindow.ratingsmisc_mpaar_RadioButton(1).Enabled = true
		  MainWindow.ratingsmisc_mpaar_RadioButton(2).Enabled = true
		  MainWindow.ratingsmisc_mpaar_RadioButton(3).Enabled = true
		  MainWindow.ratingsmisc_mpaar_RadioButton(4).Enabled = true
		  MainWindow.ratingsmisc_mpaar_RadioButton(5).Enabled = true
		  MainWindow.ratingsmisc_mpaar_RadioButton(6).Enabled = true
		  MainWindow.ratingsmisc_mpaar_RadioButton(7).Enabled = true
		  
		  MainWindow.ratingsmisc_cc_CheckBox.Enabled = true
		  MainWindow.ratingsmisc_stereo_CheckBox.Enabled = true
		  MainWindow.ratingsmisc_sap_CheckBox.Enabled = true
		  MainWindow.ratingsmisc_sub_Checkbox.Enabled = true
		  MainWindow.ratingsmisc_repeat_CheckBox.Enabled = true
		  MainWindow.ratingsmisc_hd_Checkbox.Enabled = true
		  MainWindow.ratingsmisc_letterbox_CheckBox.Enabled = true
		End Sub
	#tag EndMethod

	#tag Method, Flags = &h0
		Sub fetch_online_info_for_movie_by_id()
		  dim _dict as new dictionary
		  _dict = get_xml_for_movie_by_imdbttcode(MainWindow.IMDB_TextField.text)
		  
		  if _dict.HasKey("imdb_id") then
		    if _dict.value("imdb_id") = "tt" + MainWindow.IMDB_TextField.text then
		      // "name", "imdb_id", "overview", "rating", "released", "runtime","genre"
		      
		      if _dict.haskey("name") then MainWindow.desc_title_TextField.text = _dict.value("name")
		      if _dict.haskey("overview") then MainWindow.desc_description_TextArea.text = _dict.value("overview")
		      if _dict.haskey("genre") then MainWindow.desc_vProgramGenre_TextField.text = _dict.value("genre")
		      
		      if _dict.haskey("released") then MainWindow.desc_movieYear_TextField.text = left(_dict.value("released"),4)
		      if _dict.haskey("released") then MainWindow.desc_originalAirDate_TextField.text = _dict.value("released") + "T00:00:01Z"
		      
		      if _dict.haskey("rating") then
		        if val(_dict.value("rating")) > 6 then
		          MainWindow.desc_starRating_PopupMenu.ListIndex = 6
		        else
		          MainWindow.desc_starRating_PopupMenu.ListIndex = val(_dict.value("rating"))
		        end if
		      end if
		      
		      
		    else
		      MsgBox("IMDB does not equal suggested ID")
		    end if
		  end if
		  
		End Sub
	#tag EndMethod

	#tag Method, Flags = &h0
		Sub fetch_online_info_for_tvshow_by_id()
		  if MainWindow.EpisodeNumber_PopupMenu.ListIndex > -1 then
		    if MainWindow.Season_PopupMenu.ListIndex > -1 then
		      if MainWindow.TVSeriesId_TextField.text.len > 0 then
		        dim _dict as new dictionary
		        _dict = get_xml_for_tvshow_by_seriesid_and_season_and_string(MainWindow.ShowOrMovieType_PopupMenu.text,MainWindow.TVSeriesId_TextField.text, str(val(MainWindow.Season_PopupMenu.text)), str(val(MainWindow.EpisodeNumber_PopupMenu.text)))
		        dim valid as integer = 0
		        if _dict.HasKey("seriesid") then
		          if _dict.HasKey("EpisodeNumber") then
		            if _dict.HasKey("SeasonNumber") then
		              if val(_dict.value("EpisodeNumber")) > 0 then
		                
		                if val(_dict.value("seriesid")) > 0 then
		                  
		                  dim _dict_check_dictionary_seriesinfo_tmp as dictionary
		                  _dict_check_dictionary_seriesinfo_tmp = get_fullxml_for_seriesid(_dict.value("seriesid"))
		                  
		                  if val(MainWindow.TVSeriesId_TextField.text) = val(_dict.value("seriesid")) then
		                    valid = 1
		                    ' "EpisodeNumber", "EpisodeName", "FirstAired", "GuestStars", "Director", "Writer", "Overview", "ProductionCode", "lastupdated", "SeasonNumber", "Rating", "seriesid"
		                    
		                    if _dict_check_dictionary_seriesinfo_tmp.HasKey("Genre") then
		                      dim RegEx as new RegEx
		                      RegEx.SearchPattern = "^\|"
		                      RegEx.ReplacementPattern = ""
		                      dim genre as string = RegEx.Replace(_dict_check_dictionary_seriesinfo_tmp.value("Genre"))
		                      
		                      RegEx.SearchPattern = "\|$"
		                      RegEx.ReplacementPattern = ""
		                      genre = RegEx.Replace(genre)
		                      
		                      MainWindow.desc_vProgramGenre_TextField.text = replaceall(genre,"|",";")
		                    end if
		                    
		                    if _dict_check_dictionary_seriesinfo_tmp.HasKey("Actors") then
		                      dim RegEx as new RegEx
		                      RegEx.SearchPattern = "^\|"
		                      RegEx.ReplacementPattern = ""
		                      dim actors as string = RegEx.Replace(_dict_check_dictionary_seriesinfo_tmp.value("Actors"))
		                      
		                      RegEx.SearchPattern = "\|$"
		                      RegEx.ReplacementPattern = ""
		                      actors = RegEx.Replace(actors)
		                      
		                      MainWindow.desc_vActor_TextField.text = replaceall(actors,"|",";")
		                    end if
		                    
		                    if _dict.haskey("EpisodeName") then MainWindow.EpisodeName_change_PushButton.Enabled = true
		                    if _dict.haskey("EpisodeName") then MainWindow.episodeTitle_option_StaticText.text = _dict.value("EpisodeName")
		                    if _dict.haskey("FirstAired") then MainWindow.desc_movieYear_TextField.text = left(_dict.value("FirstAired"),4)
		                    if _dict.haskey("FirstAired") then MainWindow.desc_originalAirDate_TextField.text = _dict.value("FirstAired") + "T00:00:01Z"
		                    
		                    MainWindow.desc_seriesId_TextField.text = MainWindow.TVSeriesId_TextField.text
		                    
		                    if _dict.haskey("EpisodeNumber") then MainWindow.desc_episodeNumber_TextField.text = _dict.value("EpisodeNumber")
		                    if _dict.haskey("GuestStars") then MainWindow.desc_vGuestStar_TextField.text = _dict.value("GuestStars")
		                    if _dict.haskey("Director") then MainWindow.desc_vDirector_TextField.text = _dict.value("Director")
		                    
		                    if _dict.haskey("ExecutiveProducer") then MainWindow.desc_vExecProducer_TextField.text = _dict.value("ExecutiveProducer")
		                    if _dict.haskey("Producer") then MainWindow.desc_vProducer_TextField.text = _dict.value("Producer")
		                    
		                    if _dict.haskey("Writer") then MainWindow.desc_vWriter_TextField.text = _dict.value("Writer")
		                    if _dict.haskey("Overview") then MainWindow.desc_description_TextArea.text = _dict.value("Overview")
		                    
		                    if _dict.haskey("Rating") then
		                      if val(_dict.value("Rating")) > 6 then
		                        MainWindow.desc_starRating_PopupMenu.ListIndex = 6
		                      else
		                        MainWindow.desc_starRating_PopupMenu.ListIndex = val(_dict.value("Rating"))
		                      end if
		                    end if
		                    
		                    MainWindow.desc_isEpisode_PopupMenu.ListIndex = 1
		                    
		                  end if
		                end if
		                
		              end if
		            end if
		          end if
		        end if
		        
		        if valid = 0 then
		          MsgBox("Invalid response from server for reqest for this Series and Episode")
		        end if
		      else
		        MsgBox("A seriesid is required to search for this episode")
		      end if
		    else
		      MsgBox("A season within the seriesid: '" + MainWindow.TVSeriesId_TextField.text + "' is required to fetch the tags")
		    end if
		  else
		    MsgBox("An episode number within season: " + MainWindow.Season_PopupMenu.Text + " of seriesid: '" + MainWindow.TVSeriesId_TextField.text + "' is required to fetch the tags")
		  end if
		  
		End Sub
	#tag EndMethod

	#tag Method, Flags = &h0
		Function get_arguments_for_atomic_parsley(filename as string) As string
		  // system(qq!$AtomicParsley "$fullfile" --overWrite --stik "TV Show" --genre "TV Shows" --artist "$tmp_showname" --album "${tmp_showname}, Season $tmp_paddedseason"
		  //  --TVShowName "$tmp_showname" --TVSeasonNum $tmp_season --tracknum $tmp_s_episode --TVEpisodeNum $tmp_s_episode
		  //  --TVEpisode "${tmp_season}${tmp_paddeds_episode}" --title "$tmp_title" --year "${tmp_firstyear}-${tmp_firstmonth}-${tmp_firstday}T09:00:00Z"
		  // --comment "$tmp_summary" --description "$tmp_summary"!);
		  
		  
		  //  --rDNSatom '<?xml version="1.0" encoding="UTF-8"?><plist version="1.0"><dict> <key>cast</key> <array> <dict> <key>name</key> <string>Richard Dean Anderson</string> </dict> <dict> <key>name</key> <string>Amanda Tapping</string> </dict> <dict> <key>name</key> <string>Christopher Judg</string> </dict> <dict> <key>name</key> <string>Michael Shanks</string> </dict> </array> <key>codirectors</key> <array/> <key>directors</key> <array> <dict> <key>name</key> <string>Jonathan Glassner</string> </dict> </array> </dict></plist>' name=iTunMOVI domain=com.apple.iTunes
		  
		  dim _dict_arguments as new dictionary
		  
		  if _enable_rdns = 1 then
		    dim plist as string = "<?xml version=""1.0"" encoding=""UTF-8""?><!DOCTYPE plist PUBLIC ""-//Apple Computer//DTD PLIST 1.0//EN"" ""http://www.apple.com/DTDs/PropertyList-1.0.dtd""><plist version=""1.0""><dict>"
		    //  --rDNSatom '<?xml version="1.0" encoding="UTF-8"?><plist version="1.0"><dict> <key>cast</key> <array> <dict> <key>name</key> <string>Richard Dean Anderson</string> </dict> <dict> <key>name</key> <string>Amanda Tapping</string> </dict> <dict> <key>name</key> <string>Christopher Judg</string> </dict> <dict> <key>name</key> <string>Michael Shanks</string> </dict> </array> <key>codirectors</key> <array/> <key>directors</key> <array> <dict> <key>name</key> <string>Jonathan Glassner</string> </dict> </array> </dict></plist>' name=iTunMOVI domain=com.apple.iTunes
		    // do the cast. (actors, guest stars)
		    dim cast as string
		    if MainWindow.desc_vActor_TextField.text.len > 0 then
		      cast = MainWindow.desc_vActor_TextField.text
		    end if
		    if MainWindow.desc_vGuestStar_TextField.text.len > 0 then
		      cast = cast + ";" + MainWindow.desc_vGuestStar_TextField.text
		    end if
		    plist = plist + build_plist_for("cast",cast,";")
		    // do the directors
		    plist = plist + build_plist_for("directors",MainWindow.desc_vDirector_TextField.text,";")
		    // do the producers
		    plist = plist + build_plist_for("executive-producers",MainWindow.desc_vExecProducer_TextField.text,";")
		    plist = plist + build_plist_for("producers",MainWindow.desc_vProducer_TextField.text,";")
		    // do the writers
		    plist = plist + build_plist_for("writers",MainWindow.desc_vWriter_TextField.text,";")
		    plist = plist + "</dict></plist>"
		    
		    _dict_arguments.value("rDNSatom") = "'" + plist + "' name=iTunMOVI domain=com.apple.iTunes "
		  end if
		  
		  if _enable_rdns = 1 then
		    if MainWindow.MediaType_TextField.text = "TV Show" then
		      if  MainWindow.ratingsmisc_tvr_RadioButton(0).value then _dict_arguments.value("contentRating") = "--contentRating ""TV-Y7"" "
		      if  MainWindow.ratingsmisc_tvr_RadioButton(1).value then _dict_arguments.value("contentRating") = "--contentRating ""TV-Y"" "
		      if  MainWindow.ratingsmisc_tvr_RadioButton(2).value then _dict_arguments.value("contentRating") = "--contentRating ""TV-G"" "
		      if  MainWindow.ratingsmisc_tvr_RadioButton(3).value then _dict_arguments.value("contentRating") = "--contentRating ""TV-PG"" "
		      if  MainWindow.ratingsmisc_tvr_RadioButton(4).value then _dict_arguments.value("contentRating") = "--contentRating ""TV-14"" "
		      if  MainWindow.ratingsmisc_tvr_RadioButton(5).value then _dict_arguments.value("contentRating") = "--contentRating ""TV-MA"" "
		      if  MainWindow.ratingsmisc_tvr_RadioButton(6).value then _dict_arguments.value("contentRating") = "--contentRating ""Unrated"" "
		    else
		      if MainWindow.MediaType_TextField.text = "Movie" then
		        if  MainWindow.ratingsmisc_mpaar_RadioButton(0).value then _dict_arguments.value("contentRating") = _dict_arguments.value("contentRating")  + " --contentRating ""G"" "
		        if  MainWindow.ratingsmisc_mpaar_RadioButton(1).value then _dict_arguments.value("contentRating") = _dict_arguments.value("contentRating")  + " --contentRating ""PG"" "
		        if  MainWindow.ratingsmisc_mpaar_RadioButton(2).value then _dict_arguments.value("contentRating") = _dict_arguments.value("contentRating")  + " --contentRating ""PG-13"" "
		        if  MainWindow.ratingsmisc_mpaar_RadioButton(3).value then _dict_arguments.value("contentRating") = _dict_arguments.value("contentRating")  + " --contentRating ""NC-17"" "
		        if  MainWindow.ratingsmisc_mpaar_RadioButton(4).value then _dict_arguments.value("contentRating") = _dict_arguments.value("contentRating")  + " --contentRating ""R"" "
		        if  MainWindow.ratingsmisc_mpaar_RadioButton(5).value then _dict_arguments.value("contentRating") = _dict_arguments.value("contentRating")  + " --contentRating ""X"" "
		        if  MainWindow.ratingsmisc_mpaar_RadioButton(6).value then _dict_arguments.value("contentRating") = _dict_arguments.value("contentRating")  + " --contentRating ""Unrated"" "
		      end if
		    end if
		  end if
		  
		  // --stik "TV Show"
		  _dict_arguments.value("stik") = MainWindow.MediaType_TextField.text
		  
		  //  --genre "TV Shows"
		  if MainWindow.desc_vProgramGenre_TextField.text.len > 0 then
		    if instr(MainWindow.desc_vProgramGenre_TextField.text,";") <> 0 then
		      _dict_arguments.value("genre") = MainWindow.desc_vProgramGenre_TextField.text.NthField(";", 1)
		    else
		      _dict_arguments.value("genre") = MainWindow.desc_vProgramGenre_TextField.text
		    end if
		  else
		    _dict_arguments.value("genre") = ""
		  end if
		  
		  // --artist "$tmp_showname"
		  // --album "${tmp_showname}, Season $tmp_paddedseason"
		  // --TVShowName "$tmp_showname"
		  if MainWindow.ShowOrMovieName_TextField.text.len > 0 then
		    _dict_arguments.value("artist") = MainWindow.ShowOrMovieName_TextField.text
		    _dict_arguments.value("album") = MainWindow.ShowOrMovieName_TextField.text + ", Season " + MainWindow.Season_PopupMenu.text
		    _dict_arguments.value("TVShowName") = MainWindow.ShowOrMovieName_TextField.text
		  else
		    _dict_arguments.value("artist") = ""
		    _dict_arguments.value("album") = ""
		    _dict_arguments.value("TVShowName") = ""
		  end if
		  
		  //  --TVSeasonNum $tmp_season
		  if MainWindow.Season_PopupMenu.text.len > 0 then
		    _dict_arguments.value("TVSeasonNum") = MainWindow.Season_PopupMenu.text
		  else
		    _dict_arguments.value("TVSeasonNum") = ""
		  end if
		  
		  //  --tracknum $tmp_s_episode
		  // --TVEpisodeNum $tmp_s_episode
		  if MainWindow.EpisodeNumber_PopupMenu.text.len > 0 then
		    _dict_arguments.value("tracknum") = MainWindow.EpisodeNumber_PopupMenu.text
		    _dict_arguments.value("TVEpisodeNum") = MainWindow.EpisodeNumber_PopupMenu.text
		  else
		    _dict_arguments.value("tracknum") = ""
		    _dict_arguments.value("TVEpisodeNum") = ""
		  end if
		  
		  //  --TVEpisode "${tmp_season}${tmp_paddeds_episode}"
		  if MainWindow.Season_PopupMenu.text.len > 0 then
		    if MainWindow.desc_episodeNumber_TextField.text.len < 1 then
		      if MainWindow.EpisodeNumber_PopupMenu.text.len > 0 then
		        dim TVEpisode as integer = val(MainWindow.Season_PopupMenu.text) * 100
		        TVEpisode = TVEpisode + val(MainWindow.EpisodeNumber_PopupMenu.text)
		        _dict_arguments.value("TVEpisode") = TVEpisode
		      end if
		    else
		      _dict_arguments.value("TVEpisode") = MainWindow.EpisodeNumber_PopupMenu.text
		    end if
		  end if
		  
		  // --title "$tmp_title"
		  if MainWindow.episodeTitle_TextField.text.len > 0 then
		    _dict_arguments.value("title") = MainWindow.episodeTitle_TextField.text
		  else
		    _dict_arguments.value("title") = ""
		  end if
		  
		  // --year "${tmp_firstyear}-${tmp_firstmonth}-${tmp_firstday}T09:00:00Z"
		  if MainWindow.desc_originalAirDate_TextField.text.len > 0 then
		    _dict_arguments.value("year") = MainWindow.desc_originalAirDate_TextField.text
		  else
		    _dict_arguments.value("year") = ""
		  end if
		  
		  // --comment "$tmp_summary"
		  if MainWindow.desc_description_TextArea.text.len > 0 then
		    _dict_arguments.value("comment") = MainWindow.desc_description_TextArea.text
		  else
		    _dict_arguments.value("comment") = ""
		  end if
		  
		  // --description "$tmp_summary"
		  if MainWindow.desc_description_TextArea.text.len > 0 then
		    _dict_arguments.value("description") = MainWindow.desc_description_TextArea.text
		  else
		    _dict_arguments.value("description") = ""
		  end if
		  
		  // --encodingTool
		  _dict_arguments.value("encodingTool") = "Tago v" + str(app.MajorVersion) + "."+ str(app.MinorVersion) + "."+ str(app.BugVersion) + "."+ str(app.NonReleaseVersion)
		  
		  dim _dict_string as string = ""
		  
		  dim keys() as Variant = _dict_arguments.Keys
		  // MsgBox("Total results: " + str(ubound(keys)))
		  if ubound(keys) > 0 then
		    Dim myRegEx As new RegEx
		    myRegEx.Options.ReplaceAllMatches = true
		    
		    for each key as Variant in keys
		      myRegEx.SearchPattern = "[\n\r\f]"
		      myRegEx.Options.ReplaceAllMatches = true
		      myRegEx.ReplacementPattern = " "
		      _dict_arguments.Value(key)= myRegEx.Replace(_dict_arguments.Value(key))
		      
		      myRegEx.SearchPattern = kQuote
		      myRegEx.Options.ReplaceAllMatches = true
		      myRegEx.ReplacementPattern = kEscapedQuote
		      _dict_arguments.Value(key) = myRegEx.Replace(_dict_arguments.Value(key))
		      
		      
		      if instr(key,"contentRating") <> 0 then
		        _dict_string = _dict_string + " " + _dict_arguments.Value(key) + " "
		      else
		        if instr(key,"rDNS") <> 0 then
		          _dict_string = _dict_string + "--" + key  + " " + _dict_arguments.Value(key) + " "
		        else
		          _dict_string = _dict_string + "--" + key  + " """ + _dict_arguments.Value(key) + """ "
		        end if
		      end if
		    next
		  end if
		  
		  return _dict_string
		End Function
	#tag EndMethod

	#tag Method, Flags = &h0
		Function get_arguments_for_pytivo() As string
		  // do the cast. (actors, guest stars)
		  dim vActor as string = build_pytivo_list_for("vActor",MainWindow.desc_vActor_TextField.text,";")
		  dim vGuestStar as string = build_pytivo_list_for("vActor",MainWindow.desc_vGuestStar_TextField.text,";")
		  
		  // do the directors
		  dim vDirector as string = build_pytivo_list_for("vDirector",MainWindow.desc_vDirector_TextField.text,";")
		  
		  // do the producers
		  dim vExecProducer as string =  build_pytivo_list_for("vExecProducer",MainWindow.desc_vExecProducer_TextField.text,";")
		  dim vProducer as string = build_pytivo_list_for("vProducer",MainWindow.desc_vProducer_TextField.text,";")
		  
		  // do the writers
		  dim vWriter as string = build_pytivo_list_for("vWriter",MainWindow.desc_vWriter_TextField.text,";")
		  
		  
		  dim tvRating as string = ""
		  dim mpaaRating as string = ""
		  dim originalAirDate as string = ""
		  dim movieYear as string = ""
		  
		  if MainWindow.MediaType_TextField.text = "TV Show" then
		    originalAirDate = "originalAirDate : " + MainWindow.desc_originalAirDate_TextField.text + "" +  endofline
		    if  MainWindow.ratingsmisc_tvr_RadioButton(0).value then tvRating = "tvRating : x1"
		    if  MainWindow.ratingsmisc_tvr_RadioButton(1).value then tvRating = "tvRating : x2"
		    if  MainWindow.ratingsmisc_tvr_RadioButton(2).value then tvRating = "tvRating : x3"
		    if  MainWindow.ratingsmisc_tvr_RadioButton(3).value then tvRating = "tvRating : x4"
		    if  MainWindow.ratingsmisc_tvr_RadioButton(4).value then tvRating = "tvRating : x5"
		    if  MainWindow.ratingsmisc_tvr_RadioButton(5).value then tvRating = "tvRating : x6"
		    if  MainWindow.ratingsmisc_tvr_RadioButton(6).value then tvRating = "tvRating : x7"
		    if tvRating = "" then tvRating = "tvRating : x0"
		    tvRating = tvRating +  endofline
		  else
		    if MainWindow.MediaType_TextField.text = "Movie" then
		      movieYear  = "movieYear : " + left(MainWindow.desc_originalAirDate_TextField.text,4) + "" +  endofline
		      if  MainWindow.ratingsmisc_mpaar_RadioButton(0).value then mpaaRating = "mpaaRating : G1"
		      if  MainWindow.ratingsmisc_mpaar_RadioButton(1).value then mpaaRating = "mpaaRating : P2"
		      if  MainWindow.ratingsmisc_mpaar_RadioButton(2).value then mpaaRating = "mpaaRating : P3"
		      if  MainWindow.ratingsmisc_mpaar_RadioButton(3).value then mpaaRating = "mpaaRating : N6"
		      if  MainWindow.ratingsmisc_mpaar_RadioButton(4).value then mpaaRating = "mpaaRating : R4"
		      if  MainWindow.ratingsmisc_mpaar_RadioButton(5).value then mpaaRating = "mpaaRating : X5"
		      if mpaaRating = "" then mpaaRating = "mpaaRating : n8"
		      mpaaRating = mpaaRating +  endofline
		    end if
		  end if
		  
		  dim vProgramGenre as string = build_pytivo_list_for("vProgramGenre",MainWindow.desc_vProgramGenre_TextField.text,";")
		  // dim title as string = "seriesTitle : " + MainWindow.ShowOrMovieName_TextField.text +  endofline
		  // dim seriesTitle as string = "title : " + MainWindow.ShowOrMovieName_TextField.text +  endofline
		  dim title as string = build_pytivo_list_for("title",MainWindow.ShowOrMovieName_TextField.text,";")
		  dim seriesTitle as string = build_pytivo_list_for("seriesTitle",MainWindow.ShowOrMovieName_TextField.text,";")
		  dim episodeTitle as string = build_pytivo_list_for("episodeTitle",MainWindow.desc_episodeTitle_TextField.text,";")
		  dim description as string = "description : " + MainWindow.desc_description_TextArea.text
		  
		  Dim myRegEx As new RegEx
		  myRegEx.SearchPattern = "[\n\r\f]"
		  myRegEx.Options.ReplaceAllMatches = true
		  myRegEx.ReplacementPattern = " "
		  description = myRegEx.Replace(description) +  endofline
		  
		  dim TVEpisode as string
		  if MainWindow.desc_episodeNumber_TextField.text.len < 1 then
		    TVEpisode = str(val(MainWindow.Season_PopupMenu.text) * 100)
		    TVEpisode = str(val(TVEpisode) + val(MainWindow.EpisodeNumber_PopupMenu.text))
		  else
		    TVEpisode = MainWindow.desc_episodeNumber_TextField.text
		  end if
		  dim episodeNumber as string = "episodeNumber : " + str(TVEpisode) + "" +  endofline
		  
		  dim isEpisode as string = "isEpisode : true" +  endofline
		  if TVEpisode.len < 1 then isEpisode = "isEpisode : false" +  endofline
		  dim seriesId as string =  "seriesId : SH" + MainWindow.desc_seriesId_TextField.text + "" +  endofline
		  
		  dim showingBits_number as integer = 0
		  if MainWindow.ratingsmisc_cc_CheckBox.value then showingBits_number = showingBits_number + 1
		  if MainWindow.ratingsmisc_stereo_CheckBox.value then showingBits_number = showingBits_number + 2
		  if MainWindow.ratingsmisc_sub_Checkbox.value then showingBits_number = showingBits_number + 4
		  if MainWindow.ratingsmisc_sap_CheckBox.value then showingBits_number = showingBits_number + 32
		  if MainWindow.ratingsmisc_repeat_CheckBox.value then showingBits_number = showingBits_number + 512
		  if MainWindow.ratingsmisc_letterbox_CheckBox.value then showingBits_number = showingBits_number + 1024
		  if MainWindow.ratingsmisc_hd_Checkbox.value then showingBits_number = showingBits_number + 4096
		  if MainWindow.ratingsmisc_s_CheckBox.value then showingBits_number = showingBits_number + 65536
		  if MainWindow.ratingsmisc_v_CheckBox.value then showingBits_number = showingBits_number + 131072
		  if MainWindow.ratingsmisc_l_CheckBox.value then showingBits_number = showingBits_number + 262144
		  if MainWindow.ratingsmisc_d_CheckBox.value then showingBits_number = showingBits_number + 524288
		  if MainWindow.ratingsmisc_fv_CheckBox.value then showingBits_number = showingBits_number + 1048576
		  
		  dim showingBits as string = "showingBits : " + str(showingBits_number) + "" +  endofline
		  
		  
		  dim starRating as string = "starRating : "
		  
		  if MainWindow.desc_starRating_PopupMenu.text = "1 star" then starRating = starRating + "x1"
		  if MainWindow.desc_starRating_PopupMenu.text = "1.5 stars" then starRating = starRating + "x2"
		  if MainWindow.desc_starRating_PopupMenu.text = "2 stars" then starRating = starRating + "x3"
		  if MainWindow.desc_starRating_PopupMenu.text = "2.5 stars" then starRating = starRating + "x4"
		  if MainWindow.desc_starRating_PopupMenu.text = "3 stars" then starRating = starRating + "x5"
		  if MainWindow.desc_starRating_PopupMenu.text = "3.5 stars" then starRating = starRating + "x6"
		  if MainWindow.desc_starRating_PopupMenu.text = "4 stars" then starRating = starRating + "x7"
		  starRating = starRating +  endofline
		  
		  dim colorCode as string = "colorCode : "
		  if MainWindow.ratingsmisc_colorCode_RadioButton(0).value then colorCode = colorCode + "x1"
		  if MainWindow.ratingsmisc_colorCode_RadioButton(1).value then colorCode = colorCode + "x2"
		  if MainWindow.ratingsmisc_colorCode_RadioButton(2).value then colorCode = colorCode + "x3"
		  if MainWindow.ratingsmisc_colorCode_RadioButton(3).value then colorCode = colorCode + "x4"
		  colorCode = colorCode +  endofline
		  
		  
		  dim _dict_string as string = ""
		  
		  _dict_string = _dict_string + title
		  _dict_string = _dict_string + seriesTitle
		  _dict_string = _dict_string + episodeTitle
		  _dict_string = _dict_string + episodeNumber
		  _dict_string = _dict_string + isEpisode
		  _dict_string = _dict_string + description
		  _dict_string = _dict_string + seriesId
		  _dict_string = _dict_string + originalAirDate
		  _dict_string = _dict_string + showingBits
		  _dict_string = _dict_string + tvRating
		  _dict_string = _dict_string + mpaaRating
		  _dict_string = _dict_string + starRating
		  _dict_string = _dict_string + colorCode
		  _dict_string = _dict_string + vProgramGenre
		  _dict_string = _dict_string + vExecProducer
		  _dict_string = _dict_string + vProducer
		  _dict_string = _dict_string + vDirector
		  _dict_string = _dict_string + vActor
		  _dict_string = _dict_string + vWriter
		  _dict_string = _dict_string + vGuestStar
		  _dict_string = _dict_string + vProducer
		  _dict_string = _dict_string + movieYear
		  
		  
		  
		  return _dict_string
		End Function
	#tag EndMethod

	#tag Method, Flags = &h0
		Function get_dictionary_from_file_contents(file_contents as string) As dictionary
		  dim _dict as new dictionary
		  dim binhex_of_fields as string
		  dim myRegEx_txtfile as new RegEx
		  dim myMatch_txtfile as new RegExMatch
		  dim LinesInFile(-1) as string = split(file_contents,"|")
		  dim index as integer
		  
		  for index = 0 to ubound(LinesInFile)
		    dim the_line as string = LinesInFile(index)
		    myRegEx_txtfile.SearchPattern="^(.*?)\s:\s(.*?)$"
		    myMatch_txtfile=myRegEx_txtfile.search(the_line)
		    if  myMatch_txtfile <> Nil then
		      if left(myMatch_txtfile.SubExpressionString(1),1) = "v" then
		        dim original_string as string
		        if _dict.haskey(myMatch_txtfile.SubExpressionString(1)) then
		          original_string = _dict.value(myMatch_txtfile.SubExpressionString(1))
		        end if
		        if original_string.Len > 0 then
		          original_string = original_string + ";" + myMatch_txtfile.SubExpressionString(2)
		        else
		          original_string = myMatch_txtfile.SubExpressionString(2)
		        end if
		        _dict.value(myMatch_txtfile.SubExpressionString(1)) = original_string
		      else
		        
		        _dict.value(myMatch_txtfile.SubExpressionString(1)) = myMatch_txtfile.SubExpressionString(2)
		      end if
		    end if
		  next
		  
		  dim keys() as Variant = _dict.Keys
		  for each key as String in keys
		    binhex_of_fields = binhex_of_fields + StrToHex(key) + ":" + StrToHex(_dict.value(key)) + ";"
		  next
		  
		  
		  if _dict.haskey("title") then
		    _dict.value("valid") = 1
		    _dict.value("binhex_of_fields") = left(binhex_of_fields,len(binhex_of_fields)-1)
		  else
		    _dict.value("valid") = 0
		  end if
		  
		  
		  
		  return _dict
		  
		End Function
	#tag EndMethod

	#tag Method, Flags = &h0
		Function get_fullxml_for_seriesid(seriesid as string) As dictionary
		  Dim XMLDoc as XmlDocument = new XmlDocument
		  dim res as XmlNodeList
		  Dim myRegEx_TV As new RegEx
		  Dim myMatch_TV As new RegExMatch
		  dim _dict as new dictionary
		  
		  'if _dict_exact_series_name_to_seriesid.haskey(self.ActualFilename_StaticText.text)  then
		  '_dict_exact_series_name_to_seriesid.value(self.ActualFilename_StaticText.text)
		  'end if
		  
		  dim s as string = "http://thetvdb.com/api/" + thetvdb_apikey + "/series/" + seriesid + "/en.xml"
		  dim xml_dict as new dictionary
		  xml_dict = http_get( s ,60,1)
		  dim xmlstring as string = xml_dict.Value("http_content")
		  // MsgBox("Getting series XML: " + xmlstring)
		  if instr(xmlstring,"<Data>") <> 0 then
		    myRegEx_TV.SearchPattern="(<Series>.*?</Series>)"
		    myRegEx_TV.Options.DotMatchAll = true
		    myMatch_TV=myRegEx_TV.search(xmlstring)
		    if  myMatch_TV <> Nil then
		      Try
		        XmlDoc.PreserveWhitespace = False
		        XMLDoc.LoadXml( myMatch_TV.SubExpressionString(1))
		        dim element as string
		        for each element in Array("id", "Actors", "Airs_DayOfWeek", "Airs_Time", "ContentRating", "FirstAired","Genre", "IMDB_ID", "Language", "Network", "NetworkID", "Overview", "Rating", "Runtime", "SeriesID", "SeriesName", "Status","added","addedBy","banner","fanart","lastupdated","poster","zap2it_id")
		          res  = XmlDoc.Xql("//Series/" + element)
		          if res.Item(0).Child(0) <> nil then
		            _dict.value(element) = res.Item(0).Child(0).value
		            // MsgBox("Matched element: " + element + " with " +_dict.value(element) )
		          end if
		        next
		      Catch
		        MsgBox "Invalid XML file returned from TVDB."
		      End Try
		    end if
		  end if
		  
		  return _dict
		End Function
	#tag EndMethod

	#tag Method, Flags = &h0
		Function get_mp4_tags_from_file(filename as string, path as string, refresh_lookup as integer) As dictionary
		  dim _dict as new dictionary
		  
		  Dim myRegEx_EXTENSION As new RegEx
		  Dim myMatch_EXTENSION As new RegExMatch
		  myRegEx_EXTENSION.SearchPattern="\.(...)$"
		  myMatch_EXTENSION=myRegEx_EXTENSION.search(filename)
		  if  myMatch_EXTENSION <> Nil then
		    _dict.value("extension") = myMatch_EXTENSION.SubExpressionString(1).Lowercase
		  end if
		  
		  if not _dict.haskey("extension") then
		    return _dict
		  end if
		  if _dict.value("extension") <> "mp4" and _dict.value("extension") <> "m4v" then
		    return _dict
		  end if
		  
		  if refresh_lookup = 1 then
		    if not _dict_savedxml.haskey(StrToHex(filename)) then refresh_lookup = 1
		  end if
		  
		  if refresh_lookup = 1 then
		    
		    // MsgBox("Getting for first time")
		    dim shellpath_to_atomic_parsley_location as string = GetFolderItem(_atomic_parsley_location).ShellPath
		    dim shellpath_to_path_filename as string = GetFolderItem(path + filename).ShellPath
		    
		    Dim s_info As Shell
		    s_info=New Shell
		    s_info.execute shellpath_to_atomic_parsley_location + " " + shellpath_to_path_filename + " -T 1 "
		    If s_info.errorCode = 0 then
		      dim file_info as string = s_info.result
		      
		      Dim myRegEx_file_info As new RegEx
		      Dim myMatch_file_info As new RegExMatch
		      myRegEx_file_info.Options.DotMatchAll = true
		      
		      myRegEx_file_info.SearchPattern="Movie duration: ([\d\.]+)\s+seconds"
		      myMatch_file_info=myRegEx_file_info.search(file_info)
		      if  myMatch_file_info <> Nil then
		        _dict.value("duration") = myMatch_file_info.SubExpressionString(1)
		      end if
		      
		      myRegEx_file_info.SearchPattern="Low-level details. Total tracks: ([\d]+)"
		      myMatch_file_info=myRegEx_file_info.search(file_info)
		      if  myMatch_file_info <> Nil then
		        _dict.value("total_tracks") = myMatch_file_info.SubExpressionString(1)
		      end if
		      
		      myRegEx_file_info.SearchPattern="\s+([\d]+)x([\d]+)\s+"
		      myMatch_file_info=myRegEx_file_info.search(file_info)
		      if  myMatch_file_info <> Nil then
		        _dict.value("video_resolutionH" ) = myMatch_file_info.SubExpressionString(1)
		        _dict.value("video_resolutionV" ) = myMatch_file_info.SubExpressionString(2)
		        
		        // 4x3 = sd
		        // 480i wide & 576 wide up to 720 = edtv
		        // 720 + = hdtv
		        
		        // MsgBox("Found resolution: " +_dict.value("video_resolutionH" ) + "x" + _dict.value("video_resolutionV" )  )
		      end if
		      
		      Dim s As Shell
		      s=New Shell
		      s.execute shellpath_to_atomic_parsley_location + " " + shellpath_to_path_filename + " -t "
		      If s.errorCode = 0 then
		        if instr(s.result,"""stik"" contains: Movie") <> 0 then
		          _dict.value("valid") = 1
		          _dict.value("type") = "M"
		          _dict.value("mp4id") = 1
		        else
		          if instr(s.result,"""stik"" contains: TV Show") <> 0 then
		            _dict.value("valid") = 1
		            _dict.value("type") = "T"
		            _dict.value("mp4id") = 1
		          end if
		        end if
		        
		        if _dict.haskey("valid")  then
		          Dim myRegEx_TV As new RegEx
		          Dim myMatch_TV As new RegExMatch
		          myRegEx_TV.Options.DotMatchAll = true
		          dim element as string
		          for each element in Array("©nam", "©cmt", "©gen", "©day","©ART","©alb","©wrt", "desc", "tvsh", "gnre","tvsn","tves","tvnn","©too")
		            myRegEx_TV.SearchPattern= element +""" contains:\s+(.*?)[\n\r\f]"
		            myMatch_TV=myRegEx_TV.search(s.result)
		            if  myMatch_TV <> Nil then
		              if instr(element,"©") <> 0 then
		                _dict.value("MP4_" + right(element,3)) = myMatch_TV.SubExpressionString(1)
		              else
		                _dict.value("MP4_" + element) = myMatch_TV.SubExpressionString(1)
		              end if
		              'if element = "©nam" then _dict.value("MP4_nam") = myMatch_TV.SubExpressionString(1)
		              'if element = "©cmt" then _dict.value("MP4_cmt") = myMatch_TV.SubExpressionString(1)
		              'if element = "©gen" then _dict.value("MP4_gen") = myMatch_TV.SubExpressionString(1)
		              'if element = "©day" then _dict.value("MP4_day") = myMatch_TV.SubExpressionString(1)
		              'if element = "©ART" then _dict.value("MP4_art") = myMatch_TV.SubExpressionString(1)
		              'if element = "©alb" then _dict.value("MP4_alb") = myMatch_TV.SubExpressionString(1)
		              'if element = "©wrt" then _dict.value("MP4_wrt") = myMatch_TV.SubExpressionString(1)
		              'if element = "desc" then _dict.value("MP4_desc") = myMatch_TV.SubExpressionString(1)
		              'if element = "tvsh" then _dict.value("MP4_tvsh") = myMatch_TV.SubExpressionString(1)
		              'if element = "gnre" then _dict.value("MP4_gnre") = myMatch_TV.SubExpressionString(1)
		              'if element = "tvsn" then _dict.value("MP4_tvsn") = myMatch_TV.SubExpressionString(1)
		              'if element = "tves" then _dict.value("MP4_tves") = myMatch_TV.SubExpressionString(1)
		              'if element = "tvnn" then _dict.value("MP4_tvnn") = myMatch_TV.SubExpressionString(1)
		              'if element = "©too" then _dict.value("MP4_too") = myMatch_TV.SubExpressionString(1)
		            end if
		          next
		          
		          if  _dict.haskey("MP4_day") then
		            _dict.value("movie_year") = left( _dict.value("MP4_day"),4)
		          end if
		          
		          if  _dict.haskey("MP4_tvsn") then
		            _dict.value("season") =  _dict.value("MP4_tvsn")
		          end if
		          
		          if  _dict.haskey("MP4_tvsn") then
		            _dict.value("season") =  _dict.value("MP4_tvsn")
		          end if
		          
		          if  _dict.haskey("MP4_tves") then
		            _dict.value("episode") =  _dict.value("MP4_tves")
		          end if
		          
		          if _dict.haskey("MP4_nam") then
		            if  _dict.haskey("type") then
		              if  _dict.value("type") = "T" then
		                _dict.value("title") = _dict.value("MP4_tvsh")
		                _dict.value("episode_title") = _dict.value("MP4_nam")
		                _dict.value("file_type") = "Episide"
		              else
		                if  _dict.value("type") = "M" then
		                  _dict.value("file_type") = "Movie"
		                  _dict.value("title") = _dict.value("MP4_nam")
		                end if
		              end if
		            end if
		          end if
		          
		          if  _dict.haskey("MP4_tvsh") then
		            _dict.value("show_name") =  _dict.value("MP4_tvsh")
		          end if
		          
		        end if
		        
		        _dict_savedxml.value(StrToHex(filename)) = _dict.ExportXMLString(false)
		        
		      else
		        Msgbox "Error code while reading: "+ Str(s.errorCode)
		      end if
		    end if
		  else
		    
		    dim loaded as boolean = _dict.LoadXML(str(_dict_savedxml.value(StrToHex(filename))))
		    
		  end if
		  return _dict
		  
		End Function
	#tag EndMethod

	#tag Method, Flags = &h0
		Function get_possible_seriesid_files_in_dir(f as FolderItem) As string()
		  dim seriesids_in_dir(-1) as string
		  
		  dim i as integer
		  if f <> Nil then
		    For i=1 to f.count
		      //go through each item
		      If not f.item(i).directory then
		        if  left( f.item(i).Name,1) <> "." then
		          if right(f.item(i).Name,9) = ".seriesId" then
		            Dim f2 As FolderItem
		            Dim t2 As TextInputStream
		            f2=GetFolderItem(f.item(i).AbsolutePath)
		            If f2 <> Nil then
		              t2=f2.OpenAsTextFile
		              dim seriesid as string =t2.ReadLine
		              seriesids_in_dir.Append seriesid
		              t2.Close
		            end if
		          end if
		        end if
		        
		      end if
		    next
		  end if
		  
		  Return seriesids_in_dir()
		End Function
	#tag EndMethod

	#tag Method, Flags = &h0
		Function get_seriesid_for_seriesname(seriesname as string) As Dictionary
		  Dim XMLDoc as XmlDocument = new XmlDocument
		  dim res as XmlNodeList
		  Dim myRegEx_TV As new RegEx
		  Dim myMatch_TV As new RegExMatch
		  dim _dict as new dictionary
		  
		  'if _dict_exact_series_name_to_seriesid.haskey(self.ActualFilename_StaticText.text)  then
		  '_dict_exact_series_name_to_seriesid.value(self.ActualFilename_StaticText.text)
		  'end if
		  
		  
		  dim s as string = "http://thetvdb.com/api/GetSeries.php?seriesname=" + EncodeURLComponent(seriesname ) + "&language=all&"
		  dim xml_dict as new dictionary
		  xml_dict = http_get( s ,60,1)
		  dim xmlstring as string = xml_dict.Value("http_content")
		  
		  if instr(xmlstring,"<Data>") <> 0 then
		    myRegEx_TV.SearchPattern="(<Series>.*?</Series>)"
		    myRegEx_TV.Options.DotMatchAll = true
		    myMatch_TV=myRegEx_TV.search(xmlstring)
		    if  myMatch_TV <> Nil then
		      while myMatch_TV <> Nil
		        // dim match as string = ReplaceAll( ReplaceAll(myMatch_TV.SubExpressionString(1),"<BR>","\n"),"""","&quot;")
		        dim match as string = myMatch_TV.SubExpressionString(1)
		        Try
		          XmlDoc.PreserveWhitespace = False
		          XMLDoc.LoadXml(match)
		          
		          dim seriesid as string
		          res  = XmlDoc.Xql("//Series/seriesid" )
		          if res <> nil then
		            seriesid = res.Item(0).Child(0).value
		            if seriesid.len > 0 then
		              dim sname as string
		              res  = XmlDoc.Xql("//Series/SeriesName" )
		              if res <> nil then
		                sname = res.Item(0).Child(0).value
		                if sname.len > 0 then
		                  if sname = seriesname then
		                    _dict.value(seriesid) = myMatch_TV.SubExpressionString(1)
		                    if not _dict.haskey("valid") then _dict.value("valid") = 1
		                    return _dict
		                  end if
		                end if
		              end if
		            end if
		          end if
		        Catch
		          MsgBox "Invalid XML file returned from IMDB."
		        End Try
		        myMatch_TV=myRegEx_TV.search()
		      wend
		      
		    end if
		  end if
		  
		  return _dict
		End Function
	#tag EndMethod

	#tag Method, Flags = &h0
		Function get_series_name_for_seriesid(seriesId as string) As Dictionary
		  dim _dict as new dictionary
		  dim s as string = "http://thetvdb.com/api/" + thetvdb_apikey + "/series/" + seriesId + "/en.xml"
		  dim xml_dict as new dictionary
		  xml_dict = http_get( s ,60,1)
		  dim xmlstring as string = xml_dict.Value("http_content")
		  
		  if instr(xmlstring,"<id>") <> 0 then
		    Dim myRegEx_TV As new RegEx
		    Dim myMatch_TV As new RegExMatch
		    myRegEx_TV.SearchPattern="<SeriesName>(.*?)</SeriesName>"
		    myMatch_TV=myRegEx_TV.search(xmlstring)
		    if  myMatch_TV <> Nil then
		      _dict.value("valid") = 1
		      _dict.value("tvshow_name") = myMatch_TV.SubExpressionString(1)
		    end if
		  else
		    MsgBox("Could not find valid response during seriesId search: " + seriesId)
		  end if
		  
		  return _dict
		End Function
	#tag EndMethod

	#tag Method, Flags = &h0
		Sub get_txtfile_contents_for_movie(path as string, filename as string)
		  dim file_contents as string
		  dim tmp_filename as string = filename
		  filename = filename + ".txt"
		  
		  Dim f_txt as folderitem
		  f_txt =  GetFolderItem(path  + filename )
		  if f_txt <> nil then
		    if f_txt.Exists then
		      dim f_txt_stream as TextInputStream
		      f_txt_stream = f_txt.OpenAsTextFile
		      If f_txt_stream <> Nil then
		        // MsgBox("Opening " + filename)
		        do until  f_txt_stream.EOF
		          file_contents = file_contents + f_txt_stream.ReadLine + "|"
		        loop
		      end if
		    else
		      dim f_metadir as FolderItem = GetFolderItem(path + ".meta")
		      if f_metadir <> nil then
		        if f_metadir.Exists then
		          dim f_txt_metadir as FolderItem = GetFolderItem(f_metadir.AbsolutePath + filename)
		          if f_txt_metadir <> nil then
		            if f_txt_metadir.Exists then
		              dim f_txt_stream as TextInputStream
		              f_txt_stream = f_txt_metadir.OpenAsTextFile
		              If f_txt_stream <> Nil then
		                // MsgBox("Opening " + filename)
		                do until  f_txt_stream.EOF
		                  file_contents = file_contents + f_txt_stream.ReadLine + "|"
		                loop
		              end if
		            end if
		          end if
		        end if
		      end if
		    end if
		  end if
		  
		  _dict_savedxml.value(".meta-" +  StrToHex(tmp_filename) ) = file_contents
		  
		End Sub
	#tag EndMethod

	#tag Method, Flags = &h0
		Function get_xml_element_from_xml(xml as string, element as string) As string
		  dim xml_contents as string = "-1"
		  dim myRegEx as new RegEx
		  dim myMatch as new RegExMatch
		  
		  
		  myRegEx.SearchPattern="<" + element + ">(.*?)</" + element + ">"
		  myRegEx.Options.DotMatchAll = true
		  myMatch=myRegEx.search(xml)
		  if  myMatch <> Nil then
		    xml_contents = myMatch.SubExpressionString(1)
		  end if
		  
		  return xml_contents
		End Function
	#tag EndMethod

	#tag Method, Flags = &h0
		Function get_xml_for_movie_by_imdbttcode(imdbtxtcode as string) As dictionary
		  dim _dict as new dictionary
		  Dim myRegEx_MOVIE As new RegEx
		  Dim myMatch_MOVIE As new RegExMatch
		  dim RegEx as new RegEx
		  
		  dim s as string = themoviedb_lookupimdb_uri +  themoviedb_apikey + "/tt" + imdbtxtcode
		  dim xml_dict as new dictionary
		  xml_dict = http_get( s ,10,1)
		  dim xmlstring as string = xml_dict.Value("http_content")
		  
		  if instr(xmlstring,"OpenSearchDescription") <> 0 then
		    if instr(xmlstring,"Nothing found.") = 0 then
		      dim valid as integer = 0
		      
		      Dim XMLDoc as XmlDocument = new XmlDocument
		      Try
		        XmlDoc.PreserveWhitespace = False
		        XMLDoc.LoadXml(xmlstring)
		        dim res as XmlNodeList
		        dim element as string
		        for each element in Array("name", "imdb_id", "overview", "rating", "released", "runtime")
		          res  = XmlDoc.Xql("//movie/" + element)
		          _dict.value(element) = res.Item(0).Child(0).value
		        next
		        
		        dim genre as string = ""
		        dim i, j as Integer
		        dim attrName, attrVal As String
		        dim e as XmlElement
		        dim a As XmlAttribute
		        
		        Try
		          res  = XmlDoc.Xql("//movie/categories/category")
		          for i = 0 to res.Length - 1
		            e = XmlElement(res.Item(i))
		            for j = 0 to e.AttributeCount
		              a = e.GetAttributeNode(j)
		              if a <> nil then
		                attrName = a.Name
		                attrVal = a.Value
		                if attrName = "name" then
		                  genre = genre + attrVal + ";"
		                end if
		              end if
		            next
		          next
		          if genre.Len> 0 then
		            RegEx.SearchPattern = ";$"
		            RegEx.ReplacementPattern = ""
		            _dict.value("genre") = RegEx.Replace(genre)
		          end if
		        Catch
		          MsgBox "Invalid XML file returned from //movie/categories/category"
		        end try
		      Catch
		        MsgBox "Invalid XML file returned from IMDB."
		      End Try
		    else
		      MsgBox("Could not fetch movie information for: " + imdbtxtcode + ".  Are you sure this is the correct IMDB code number?")
		    end if
		  else
		    MsgBox("Could not fetch movie information for: " + imdbtxtcode + ".  The site may be down?")
		  end if
		  
		  return _dict
		  
		  
		  '<?xml version="1.0" encoding="UTF-8"?>
		  '<OpenSearchDescription xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/">
		  '<movies>
		  '<movie>
		  '<popularity>3</popularity>
		  '<name>The Nightmare Before Christmas</name>
		  '<alternative_name></alternative_name>
		  '<type>movie</type>
		  '<id>9479</id>
		  '<imdb_id>tt0107688</imdb_id>
		  '<url>http://www.themoviedb.org/movie/9479</url>
		  '<overview>Can Christmas be saved? Bored with the same old scare-and-scream routine, Jack Skellington, the Pumpkin King of Halloween Town, longs to spread the joy of Christmas. But his merry mission puts Santa in jeopardy and creates a nightmare for good little boys and girls everywhere!</overview>
		  '<rating>7.25</rating>
		  '<released>1993-10-09</released>
		  '<runtime>76</runtime>
		  '<categories>
		  '<category type="genre" url="http://themoviedb.org/encyclopedia/category/16" name="Animation"/>
		  '<category type="genre" url="http://themoviedb.org/encyclopedia/category/14" name="Fantasy"/>
		  '</categories>
		  '<images>
		  '<image type="poster" size="original" url="http://images.themoviedb.org/posters/2761/The_Nightmare_Before_Christmas_poster.jpg" id="2761"/>
		  '<image type="poster" size="cover" url="http://images.themoviedb.org/posters/2761/The_Nightmare_Before_Christmas_poster_cover.jpg" id="2761"/>
		  '<image type="poster" size="mid" url="http://images.themoviedb.org/posters/2761/The_Nightmare_Before_Christmas_poster_mid.jpg" id="2761"/>
		  '<image type="poster" size="thumb" url="http://images.themoviedb.org/posters/2761/The_Nightmare_Before_Christmas_poster_thumb.jpg" id="2761"/>
		  '<image type="backdrop" size="original" url="http://images.themoviedb.org/backdrops/14717/Nightmare_Before_Christmas-fanart.jpg" id="14717"/>
		  '<image type="backdrop" size="poster" url="http://images.themoviedb.org/backdrops/14717/Nightmare_Before_Christmas-fanart_poster.jpg" id="14717"/>
		  '<image type="backdrop" size="thumb" url="http://images.themoviedb.org/backdrops/14717/Nightmare_Before_Christmas-fanart_thumb.jpg" id="14717"/>
		  '<image type="backdrop" size="original" url="http://images.themoviedb.org/backdrops/11534/14.jpg" id="11534"/>
		  '<image type="backdrop" size="poster" url="http://images.themoviedb.org/backdrops/11534/14_poster.jpg" id="11534"/>
		  '<image type="backdrop" size="thumb" url="http://images.themoviedb.org/backdrops/11534/14_thumb.jpg" id="11534"/>
		  '<image type="backdrop" size="original" url="http://images.themoviedb.org/backdrops/74/tt0107688.jpg" id="74"/>
		  '<image type="backdrop" size="thumb" url="http://images.themoviedb.org/backdrops/74/tt0107688_thumb.jpg" id="74"/>
		  '<image type="backdrop" size="poster" url="http://images.themoviedb.org/backdrops/74/tt0107688_poster.jpg" id="74"/>
		  '</images>
		  '</movie>
		  '</movies>
		  '</OpenSearchDescription>
		  
		End Function
	#tag EndMethod

	#tag Method, Flags = &h0
		Function get_xml_for_tvshow_by_seriesid_and_season_and_string(episodetype as string, seriesid as string, season as string, episode as string) As dictionary
		  dim RegEx as new RegEx
		  
		  dim _dict as new dictionary
		  
		  if instr(episodetype,"Commentary") <> 0 or  instr(episodetype,"Special") <> 0  then
		    season = "0"
		  end if
		  
		  
		  // http://www.thetvdb.com/api/01D7C3B81B7DADE8/series/73255/default/5/20/en.xml
		  
		  dim s as string = thetvdb_getepisodeinfo +  thetvdb_apikey + "/series/" + seriesid + "/default/" + season + "/" + episode + "/en.xml"
		  dim xml_dict as new dictionary
		  xml_dict = http_get( s ,60,1)
		  dim xmlstring as string = xml_dict.Value("http_content")
		  
		  
		  // MsgBox(xmlstring)
		  
		  if instr(xmlstring,"<Data>") <> 0 then
		    dim element as string
		    for each element in Array("EpisodeNumber", "EpisodeName", "FirstAired", "GuestStars", "Director", "Writer", "Overview", "ProductionCode", "lastupdated", "SeasonNumber","Rating","seriesid")
		      dim contents as string = get_xml_element_from_xml(xmlstring,element)
		      if element <> "-1" then
		        RegEx.SearchPattern = "^\|"
		        RegEx.ReplacementPattern = ""
		        contents = RegEx.Replace(contents)
		        
		        RegEx.SearchPattern = "\|$"
		        RegEx.ReplacementPattern = ""
		        contents = RegEx.Replace(contents)
		        
		        _dict.value(element) = replaceall(contents,"|",";")
		      end if
		    next
		  else
		    MsgBox("Could not fetch TV Show information for seriesid: " + seriesid + ".  Are you sure this is the correct seriesid?")
		  end if
		  
		  return _dict
		  
		  '<?xml version="1.0" encoding="UTF-8" ?>
		  '<Data><Episode>
		  '<id>440836</id>
		  '<seasonid>34608</seasonid>
		  '<EpisodeNumber>20</EpisodeNumber>
		  '<EpisodeName>Simple Explanation</EpisodeName>
		  '<FirstAired>2009-04-06</FirstAired>
		  '<GuestStars>Meat Loaf</GuestStars>
		  '<Director>Greg Yaitanes</Director>
		  '<Writer>Leonard Dick</Writer>
		  '<Overview>Charlotte, an older woman who has spent the last six months taking care of her dying husband Eddie, is rushed to Princeton Plainsboro after collapsing from respiratory failure. The couple becomes a double mystery for the team when Eddie begins to improve as Charlotte’s condition worsens. The previously unthinkable becomes real when it seems that Charlotte will die before Eddie, and the team will be forced to make a difficult decision.</Overview>
		  '<ProductionCode>HOU-520</ProductionCode>
		  '<lastupdated>1247500925</lastupdated>
		  '<flagged>0</flagged>
		  '<DVD_discid></DVD_discid>
		  '<DVD_season></DVD_season>
		  '<DVD_episodenumber></DVD_episodenumber>
		  '<DVD_chapter></DVD_chapter>
		  '<absolute_number>106</absolute_number>
		  '<filename>episodes/73255/440836.jpg</filename>
		  '<seriesid>73255</seriesid>
		  '<mirrorupdate>2009-07-13 09:02:05</mirrorupdate>
		  '<IMDB_ID></IMDB_ID>
		  '<EpImgFlag>2</EpImgFlag>
		  '<Rating>8.3</Rating>
		  '<SeasonNumber>5</SeasonNumber>
		  '<Language>en</Language>
		  '</Episode></Data>
		  
		End Function
	#tag EndMethod

	#tag Method, Flags = &h0
		Function HexToStr(HexToStr As String) As String
		  Dim strTemp   As String
		  Dim strReturn As String
		  Dim I         As integer
		  
		  For I = 1 To Len(HexToStr) Step 2
		    strTemp = Chr(Val("&H" + Mid(HexToStr, I, 2)))
		    strReturn = strReturn + strTemp
		  Next I
		  return strReturn
		  
		  // Exception err
		  // HandleMyError(err, CurrentMethodName)
		End Function
	#tag EndMethod

	#tag Method, Flags = &h0
		Function http_get(s as string, timeout as integer, yield as integer) As dictionary
		  dim http_dict as new dictionary
		  
		  if timeout < 1 then
		    timeout = 60
		  end if
		  
		  if use_curl = 1 then
		    if instr(s,"get_mess") < 1 and instr(s,"bfs_im") < 1 then
		      // MsgBox("Curl Getting " + s)
		    end if
		    _filesize = -1
		    dim d as new DownloadCURL
		    d.OptionURL= s
		    d.OptionTimeOut = timeout
		    if yield = 1 then
		      d.YieldTime = true
		    end if
		    
		    dim e as integer = d.perform
		    http_dict.Value("http_content") = d.datas
		    http_dict.Value("http_content_length") = str( d.datas.len)
		    http_dict.value("last_errorcode") = str(e)
		  else
		    if instr(s,"get_mess") < 1 and instr(s,"bfs_im") < 1 then
		      // MsgBox("HTTPSocket Getting " + s)
		    end if
		    dim sock As new HTTPSocket
		    if yield = 1 then
		      sock.Yield = true
		    end if
		    http_dict.Value("http_content")  =  sock.Get( s, timeout )
		    http_dict.Value("http_content_length") = str(http_dict.Value("http_content").len)
		    http_dict.value("last_errorcode") = str(sock.LastErrorCode)
		  end if
		  return http_dict
		  
		  // Exception err
		  // HandleMyError(err, CurrentMethodName)
		End Function
	#tag EndMethod

	#tag Method, Flags = &h0
		Function http_post(s as string, timeout as integer, dict as dictionary, yield as integer) As string
		  dim string_encoded_vals as string
		  dim xmlstring as string
		  dim sock As new HTTPSocket
		  if yield = 1 then
		    sock.Yield = true
		  end if
		  
		  string_encoded_vals = sock.EncodeFormData(dict)
		  sock.SetPostContent(string_encoded_vals,"application/x-www-form-urlencoded")
		  xmlstring =  sock.Post( s , timeout )
		  
		  return xmlstring
		  
		  // Exception err
		  // HandleMyError(err, CurrentMethodName)
		End Function
	#tag EndMethod

	#tag Method, Flags = &h0
		Sub mark_desc_page_using_showingBits(tmp_dictionary as dictionary)
		  if tmp_dictionary.haskey("showingBits") then
		    dim showingBits as Int64 = val(tmp_dictionary.value("showingBits"))
		    dim keys() as Variant = _dict_showingBits.Keys
		    for each key as String in keys
		      if BitWise.BitAnd(showingBits,val(key)) > 0 then
		        // MsgBox(_dict_showingBits.Value(key) + " is true")
		        select case val(key)
		        case 1
		          MainWindow.ratingsmisc_cc_CheckBox.value = true
		        case 2
		          MainWindow.ratingsmisc_stereo_CheckBox.value = true
		        case 4
		          MainWindow.ratingsmisc_sub_Checkbox.value = true
		        case 32
		          MainWindow.ratingsmisc_sap_CheckBox.value = true
		        case 512
		          MainWindow.ratingsmisc_repeat_CheckBox.value = true
		        case 1024
		          MainWindow.ratingsmisc_letterbox_CheckBox.value = true
		        case 4096
		          MainWindow.ratingsmisc_hd_Checkbox.value = true
		        case 65536
		          MainWindow.ratingsmisc_s_CheckBox.value = true
		        case 131072
		          MainWindow.ratingsmisc_v_CheckBox.value = true
		        case 262144
		          MainWindow.ratingsmisc_l_CheckBox.value = true
		        case 524288
		          MainWindow.ratingsmisc_d_CheckBox.value = true
		        case 1048576
		          MainWindow.ratingsmisc_fv_CheckBox.value = true
		        end select
		      end if
		    next
		  end if
		End Sub
	#tag EndMethod

	#tag Method, Flags = &h0
		Function parse_season_episode_from_number(season_episode as string) As string()
		  dim season_episode_array() as string
		  dim season as string = "?"
		  dim episode as string = "?"
		  
		  Dim myRegEx_SEASONEPISODE As new RegEx
		  Dim myMatch_SEASONEPISODE As new RegExMatch
		  
		  myRegEx_SEASONEPISODE.SearchPattern="^([\d]+)([\d]{2})$"
		  myMatch_SEASONEPISODE=myRegEx_SEASONEPISODE.search(season_episode)
		  if  myMatch_SEASONEPISODE <> Nil then
		    season = myMatch_SEASONEPISODE.SubExpressionString(1)
		    episode = myMatch_SEASONEPISODE.SubExpressionString(2)
		  end if
		  
		  season_episode_array.Append season
		  season_episode_array.Append episode
		  
		  return season_episode_array()
		End Function
	#tag EndMethod

	#tag Method, Flags = &h0
		Sub populate_info_for_movie(check_dictionary as dictionary)
		  
		  if check_dictionary.haskey("movie_name") then
		    MainWindow.ShowOrMovieName_TextField.text = check_dictionary.value("movie_name")
		    MainWindow.desc_title_TextField.Text = check_dictionary.Value("movie_name")
		  end if
		  
		  MainWindow.ShowOrMovieType_PopupMenu.listindex = 3
		  
		  if check_dictionary.haskey("file_type") then
		    if check_dictionary.value("file_type") = "Movie" then MainWindow.ShowOrMovieType_PopupMenu.listindex = 3
		    if check_dictionary.value("file_type") = "Commentary" then MainWindow.ShowOrMovieType_PopupMenu.listindex = 4
		    if check_dictionary.value("file_type") = "Special" then MainWindow.ShowOrMovieType_PopupMenu.listindex = 5
		  end if
		  
		  // MainWindow.IMDB_TextField.text  = ""
		  if check_dictionary.haskey("imdb_number") then MainWindow.IMDB_TextField.text = check_dictionary.value("imdb_number")
		  
		  // MainWindow.Year_TextField.text  = ""
		  if check_dictionary.haskey("movie_year") then MainWindow.Year_TextField.text = check_dictionary.value("movie_year")
		  if check_dictionary.haskey("movie_year") then MainWindow.desc_movieYear_TextField.text = check_dictionary.value("movie_year")
		  MainWindow.MediaType_TextField.Text= "Movie"
		  
		  // MainWindow.episodeTitle_TextField.text  = ""
		  // if check_dictionary.haskey("episode_title") then MainWindow.episodeTitle_TextField.text = check_dictionary.value("episode_title")
		  
		  if check_dictionary.haskey("svldfv_rating") then
		    if instr(check_dictionary.value("svldfv_rating"),"S") <> 0 then
		      MainWindow.sr_s_CheckBox.value = true
		    end if
		    if instr(check_dictionary.value("svldfv_rating"),"V") <> 0 then
		      MainWindow.sr_v_CheckBox.value = true
		    end if
		    if instr(check_dictionary.value("svldfv_rating"),"L") <> 0 then
		      MainWindow.sr_l_CheckBox.value = true
		    end if
		    if instr(check_dictionary.value("svldfv_rating"),"D") <> 0 then
		      MainWindow.sr_d_CheckBox.value = true
		    end if
		    if instr(check_dictionary.value("svldfv_rating"),"F") <> 0 then
		      MainWindow.sr_fv_CheckBox.value = true
		    end if
		  end if
		  
		  MainWindow.mpaar_RadioButton(7).Value = true
		  if check_dictionary.haskey("movie_rating") then
		    if check_dictionary.value("movie_rating") = "X" then
		      MainWindow.mpaar_RadioButton(5).Value = true
		    end if
		    if check_dictionary.value("movie_rating") = "R" then
		      MainWindow.mpaar_RadioButton(4).Value = true
		    end if
		    if check_dictionary.value("movie_rating") = "13" then
		      MainWindow.mpaar_RadioButton(2).Value = true
		    end if
		    if check_dictionary.value("movie_rating") = "PG" then
		      MainWindow.mpaar_RadioButton(1).Value = true
		    end if
		    if check_dictionary.value("movie_rating") = "G" then
		      MainWindow.mpaar_RadioButton(0).Value = true
		    end if
		    if check_dictionary.value("movie_rating") = "17" then
		      MainWindow.mpaar_RadioButton(3).Value = true
		    end if
		    if check_dictionary.value("movie_rating") = "NR" then
		      MainWindow.mpaar_RadioButton(6).Value = true
		    end if
		  end if
		  
		  MainWindow.tvr_RadioButton(7).Value = true
		  if check_dictionary.haskey("tv_rating") then
		    if check_dictionary.value("tv_rating") = "PG" then
		      MainWindow.tvr_RadioButton(4).Value = true
		    end if
		    if check_dictionary.value("tv_rating") = "G" then
		      MainWindow.tvr_RadioButton(2).Value = true
		    end if
		    if check_dictionary.value("tv_rating") = "14" then
		      MainWindow.tvr_RadioButton(3).Value = true
		    end if
		    if check_dictionary.value("tv_rating") = "Y7" then
		      MainWindow.tvr_RadioButton(0).Value = true
		    end if
		    if check_dictionary.value("tv_rating") = "Y" then
		      MainWindow.tvr_RadioButton(1).Value = true
		    end if
		    if check_dictionary.value("tv_rating") = "MA" then
		      MainWindow.tvr_RadioButton(5).Value = true
		    end if
		    if check_dictionary.value("tv_rating") = "NR" then
		      MainWindow.tvr_RadioButton(6).Value = true
		    end if
		    if check_dictionary.value("tv_rating") = "NoR" then
		      MainWindow.tvr_RadioButton(7).Value = true
		    end if
		  end if
		  
		  if check_dictionary.haskey("title") then
		    if MainWindow.desc_title_TextField.text.Len < 1 then
		      MainWindow.desc_title_TextField.Text = check_dictionary.Value("title")
		    end if
		    if MainWindow.ShowOrMovieName_TextField.text.Len < 1 then
		      MainWindow.ShowOrMovieName_TextField.text = check_dictionary.Value("title")
		    end if
		  end if
		  
		  if check_dictionary.haskey("episode_title") then MainWindow.desc_episodeTitle_TextField.Text = check_dictionary.value("episode_title")
		  
		End Sub
	#tag EndMethod

	#tag Method, Flags = &h0
		Sub populate_info_for_tvshow(check_dictionary as dictionary)
		  if check_dictionary.haskey("show_name")  then
		    
		    if  _dict_savedxml.haskey(StrToHex(check_dictionary.value("show_name")))   then
		      // MsgBox("Getting cached seriesnames for searcid")
		      dim loaded as boolean = _dict_series_names_search.LoadXML(str(_dict_savedxml.value(StrToHex(check_dictionary.value("show_name")))))
		    end if
		    
		    _dict_savedxml.value(StrToHex(check_dictionary.value("show_name"))) = _dict_series_names_search.ExportXMLString(false)
		    
		    if not _dict_series_names_search.HasKey("valid") then
		      // MsgBox("Refetching from server cos we did not get valid result")
		      _dict_series_names_search = get_seriesid_for_seriesname(check_dictionary.value("show_name"))
		    end if
		    
		    if _dict_series_names_search.HasKey("valid") then
		      _dict_savedxml.value(StrToHex(check_dictionary.value("show_name"))) = _dict_series_names_search.ExportXMLString(false)
		      
		      dim keys() as Variant = _dict_series_names_search.Keys
		      // MsgBox("Total results: " + str(ubound(keys)))
		      if ubound(keys) > 0 then
		        Dim XMLDoc as XmlDocument = new XmlDocument
		        dim res as XmlNodeList
		        
		        for each key as Variant in keys
		          if key <> "valid" then
		            MainWindow.possibleseriesids_StaticText.text = str(val(MainWindow.possibleseriesids_StaticText.text) + 1)
		            // MainWindow.TVSeriesId_TextField.text = key
		            // MsgBox("INDEX: " + key + " is " + _dict_series_names_search.value(key))
		            dim xmlstring as string =  _dict_series_names_search.value(key)
		            if instr(xmlstring,"<Series>") <> 0 then
		              XmlDoc.PreserveWhitespace = False
		              try
		                XMLDoc.LoadXml(xmlstring)
		                res  = XmlDoc.Xql("//Series/SeriesName" )
		                if res <> nil then
		                  if res.Item(0).Child(0).value = check_dictionary.value("show_name") then
		                    MainWindow.TVSeriesId_TextField.text = key
		                    res  = XmlDoc.Xql("//Series/Overview" )
		                    if res <> nil then
		                      _found_series_overview = res.Item(0).Child(0).value
		                    end if
		                    res  = XmlDoc.Xql("//Series/SeriesName" )
		                    if res <> nil then
		                      _found_series_name = res.Item(0).Child(0).value
		                    end if
		                  end if
		                end if
		                
		              Catch
		                MsgBox "Invalid XML file returned from IMDB."
		              End Try
		              
		            end if
		          end if
		        next
		      else
		        // cycle through all keys, skipping 'valid' and display to user to choose.
		      end if
		    end if
		    
		    
		  else
		    MsgBox("Because Tago cannot parse out the series name from this filename or MP4 tag, you will have to search for the file using the form in the lower left of the screen.")
		  end if
		  
		  if check_dictionary.haskey("show_name") then MainWindow.ShowOrMovieName_TextField.text = check_dictionary.value("show_name")
		  if check_dictionary.haskey("show_name") then MainWindow.desc_title_TextField.text = check_dictionary.value("show_name")
		  
		  MainWindow.ShowOrMovieType_PopupMenu.listindex = 0
		  
		  if check_dictionary.haskey("file_type") then
		    if check_dictionary.value("file_type") = "Movie" then MainWindow.ShowOrMovieType_PopupMenu.listindex = 3
		    if check_dictionary.value("file_type") = "Commentary" then MainWindow.ShowOrMovieType_PopupMenu.listindex =  1
		    if check_dictionary.value("file_type") = "Special" then MainWindow.ShowOrMovieType_PopupMenu.listindex =2
		  end if
		  MainWindow.MediaType_TextField.Text= "TV Show"
		  
		  // MainWindow.Year_TextField.text  = ""
		  if check_dictionary.haskey("movie_year") then MainWindow.Year_TextField.text = check_dictionary.value("movie_year")
		  if check_dictionary.haskey("movie_year") then MainWindow.desc_movieYear_TextField.text = check_dictionary.value("movie_year")
		  
		  // MainWindow.episodeTitle_TextField.text  = ""
		  if check_dictionary.haskey("episode_title") then MainWindow.episodeTitle_TextField.text = check_dictionary.value("episode_title")
		  
		  // MainWindow.Season_PopupMenu.ListIndex = -1
		  if check_dictionary.haskey("season") then MainWindow.Season_PopupMenu.ListIndex = val(check_dictionary.Value("season"))
		  
		  // MainWindow.EpisodeNumber_PopupMenu.ListIndex = -1
		  if check_dictionary.haskey("episode") then MainWindow.EpisodeNumber_PopupMenu.ListIndex = val(check_dictionary.Value("episode")) - 1
		  
		  
		  if check_dictionary.haskey("title") then
		    MainWindow.desc_title_TextField.Text = check_dictionary.Value("title")
		  end if
		  
		  if check_dictionary.haskey("episode_title") then MainWindow.desc_episodeTitle_TextField.Text = check_dictionary.value("episode_title")
		  
		End Sub
	#tag EndMethod

	#tag Method, Flags = &h0
		Sub populate_info_from_meta_file(check_dictionary as dictionary)
		  // MsgBox("Getting info from metadata file in dictionary")
		  dim tmp_dictionary as new dictionary
		  if _dict_savedxml.haskey(".meta-" + StrToHex(MainWindow.ActualFilename_StaticText.text) ) then tmp_dictionary = get_dictionary_from_file_contents(_dict_savedxml.value(".meta-" +StrToHex(MainWindow.ActualFilename_StaticText.text )))
		  if tmp_dictionary.haskey("valid") then
		    if tmp_dictionary.Value("valid") = "1" then
		      if tmp_dictionary.haskey("title") then
		        if MainWindow.desc_title_TextField.Text.Len< 1 then
		          MainWindow.desc_title_TextField.Text = tmp_dictionary.Value("title")
		        end if
		        if MainWindow.ShowOrMovieName_TextField.Text.Len< 1 then
		          MainWindow.ShowOrMovieName_TextField.Text = tmp_dictionary.Value("title")
		        end if
		      end if
		      if MainWindow.desc_episodeTitle_TextField.Text.Len< 1 then
		        if tmp_dictionary.haskey("episodeTitle") then MainWindow.desc_episodeTitle_TextField.Text = tmp_dictionary.value("episodeTitle")
		      end if
		      
		      if tmp_dictionary.haskey("episodeTitle") then MainWindow.episodeTitle_TextField.Text = tmp_dictionary.Value("episodeTitle")
		      if tmp_dictionary.haskey("movieYear") then MainWindow.desc_movieYear_TextField.Text = tmp_dictionary.Value("movieYear")
		      if tmp_dictionary.haskey("movieYear") then MainWindow.Year_TextField.Text = tmp_dictionary.Value("movieYear")
		      if tmp_dictionary.haskey("originalAirDate") then
		        MainWindow.desc_originalAirDate_TextField.Text = tmp_dictionary.Value("originalAirDate")
		        if MainWindow.desc_movieYear_TextField.Text.Len <> 4 then
		          MainWindow.desc_movieYear_TextField.Text = left(tmp_dictionary.Value("originalAirDate"),4)
		        end if
		        if MainWindow.Year_TextField.Text.Len <> 4 then
		          MainWindow.Year_TextField.Text = left(tmp_dictionary.Value("originalAirDate"),4)
		        end if
		      end if
		      if tmp_dictionary.haskey("seriesId") then MainWindow.desc_seriesId_TextField.Text = tmp_dictionary.Value("seriesId")
		      
		      // MainWindow.Season_PopupMenu.ListIndex = -1
		      if check_dictionary.haskey("season") then MainWindow.Season_PopupMenu.ListIndex = val(check_dictionary.Value("season"))
		      
		      // MainWindow.EpisodeNumber_PopupMenu.ListIndex = -1
		      if check_dictionary.haskey("episode") then MainWindow.EpisodeNumber_PopupMenu.ListIndex = val(check_dictionary.Value("episode")) - 1
		      
		      if tmp_dictionary.haskey("isEpisode") then
		        // MsgBox("is episode: " + tmp_dictionary.Value("isEpisode"))
		        if  tmp_dictionary.Value("isEpisode") = "false" then
		          MainWindow.desc_isEpisode_PopupMenu.ListIndex = 0
		        else
		          if  tmp_dictionary.Value("isEpisode") = "true" then
		            MainWindow.desc_isEpisode_PopupMenu.ListIndex = 1
		            if tmp_dictionary.haskey("seriesId") then MainWindow.desc_seriesId_TextField.Text = tmp_dictionary.Value("seriesId")
		            if tmp_dictionary.haskey("episodeTitle") then MainWindow.desc_episodeTitle_TextField.Text = tmp_dictionary.Value("episodeTitle")
		            if tmp_dictionary.haskey("episodeNumber") then MainWindow.desc_episodeNumber_TextField.Text = tmp_dictionary.Value("episodeNumber")
		          end if
		        end if
		      end if
		      
		      if tmp_dictionary.haskey("vProgramGenre") then MainWindow.desc_vProgramGenre_TextField.Text = tmp_dictionary.Value("vProgramGenre")
		      if tmp_dictionary.haskey("vActor") then MainWindow.desc_vActor_TextField.Text = tmp_dictionary.Value("vActor")
		      if tmp_dictionary.haskey("vGuestStar") then MainWindow.desc_vGuestStar_TextField.Text = tmp_dictionary.Value("vGuestStar")
		      if tmp_dictionary.haskey("vDirector") then MainWindow.desc_vDirector_TextField.Text = tmp_dictionary.Value("vDirector")
		      if tmp_dictionary.haskey("vExecProducer") then MainWindow.desc_vExecProducer_TextField.Text = tmp_dictionary.Value("vExecProducer")
		      if tmp_dictionary.haskey("vProducer") then MainWindow.desc_vProducer_TextField.Text = tmp_dictionary.Value("vProducer")
		      if tmp_dictionary.haskey("vWriter") then MainWindow.desc_vWriter_TextField.Text = tmp_dictionary.Value("vWriter")
		      
		      if tmp_dictionary.haskey("tvRating") then
		        if  tmp_dictionary.value("tvRating") = "x0" then  MainWindow.ratingsmisc_tvr_RadioButton(7).value = true
		        if  tmp_dictionary.value("tvRating") = "x1" then  MainWindow.ratingsmisc_tvr_RadioButton(0).value= true
		        if  tmp_dictionary.value("tvRating") = "x2" then  MainWindow.ratingsmisc_tvr_RadioButton(1).value = true
		        if  tmp_dictionary.value("tvRating") = "x3" then  MainWindow.ratingsmisc_tvr_RadioButton(2).value = true
		        if  tmp_dictionary.value("tvRating") = "x4" then  MainWindow.ratingsmisc_tvr_RadioButton(3).value = true
		        if  tmp_dictionary.value("tvRating") = "x5" then  MainWindow.ratingsmisc_tvr_RadioButton(4).value = true
		        if  tmp_dictionary.value("tvRating") = "x6" then  MainWindow.ratingsmisc_tvr_RadioButton(5).value = true
		        if  tmp_dictionary.value("tvRating") = "x7" then  MainWindow.ratingsmisc_tvr_RadioButton(6).value = true
		      end if
		      
		      if tmp_dictionary.haskey("mpaaRating") then
		        if  tmp_dictionary.value("mpaaRating") = "G1" then  MainWindow.ratingsmisc_mpaar_RadioButton(0).value = true
		        if  tmp_dictionary.value("mpaaRating") = "P2" then  MainWindow.ratingsmisc_mpaar_RadioButton(1).value= true
		        if  tmp_dictionary.value("mpaaRating") = "P3" then  MainWindow.ratingsmisc_mpaar_RadioButton(2).value = true
		        if  tmp_dictionary.value("mpaaRating") = "R4" then  MainWindow.ratingsmisc_mpaar_RadioButton(4).value = true
		        if  tmp_dictionary.value("mpaaRating") = "X5" then  MainWindow.ratingsmisc_mpaar_RadioButton(5).value = true
		        if  tmp_dictionary.value("mpaaRating") = "N6" then  MainWindow.ratingsmisc_mpaar_RadioButton(3).value = true
		        if  tmp_dictionary.value("mpaaRating") = "N8" then  MainWindow.ratingsmisc_mpaar_RadioButton(6).value = true
		      end if
		      
		      if tmp_dictionary.haskey("colorCode") then
		        if  tmp_dictionary.value("colorCode") = "X1" then MainWindow.ratingsmisc_colorCode_RadioButton(0).value = true
		        if  tmp_dictionary.value("colorCode") = "X2" then MainWindow.ratingsmisc_colorCode_RadioButton(1).value = true
		        if  tmp_dictionary.value("colorCode") = "X3" then MainWindow.ratingsmisc_colorCode_RadioButton(2).value = true
		        if  tmp_dictionary.value("colorCode") = "X4" then MainWindow.ratingsmisc_colorCode_RadioButton(3).value = true
		      end if
		      
		      
		      // MainWindow.desc_starRating_PopupMenu.ListIndex = -1
		      if tmp_dictionary.haskey("starRating") then
		        dim rating as integer = val(right(tmp_dictionary.value("starRating"),1)) - 1
		        MainWindow.desc_starRating_PopupMenu.ListIndex = rating
		      end if
		      
		      mark_desc_page_using_showingBits(tmp_dictionary)
		    end if
		  end if
		End Sub
	#tag EndMethod

	#tag Method, Flags = &h0
		Sub populate_listbox_with_folder_contents(f as FolderItem, clear_listbox as integer)
		  _already_said_okay = 0
		  dim i as integer
		  dim index as integer
		  dim check_dictionary as new Dictionary
		  
		  
		  MainWindow.FileList_Listbox.Enabled = false
		  MainWindow.FileList_Listbox.refresh
		  MainWindow.FileList_ProgressWheel.visible = true
		  MainWindow.FileList_ProgressWheel.Enabled = true
		  MainWindow.FileList_ProgressWheel.Refresh
		  if clear_listbox = 1 then
		    MainWindow.FileList_Listbox.DeleteAllRows
		    _listbox_totalcount = 0
		    _listbox_directories = 0
		  end if
		  
		  dim seriesids_in_dir() as string
		  seriesids_in_dir() = get_possible_seriesid_files_in_dir(GetFolderItem(f.AbsolutePath))
		  
		  if ubound(seriesids_in_dir) > 0 then
		    for index = 0 to ubound(seriesids_in_dir)
		      dim _dict_series_names_file as new dictionary
		      _dict_series_names_file = get_series_name_for_seriesid(seriesids_in_dir(index))
		      if _dict_series_names_file.HasKey("valid") then
		        if _dict_series_names_file.haskey("tvshow_name") then
		          _dict_seriesid_files.value(seriesids_in_dir(index)) = _dict_series_names_file.value("tvshow_name")
		        end if
		      end if
		    next
		  end if
		  
		  For i=1 to f.count
		    MainWindow.FileList_ProgressWheel.Refresh
		    If f.item(i).directory then
		      _listbox_directories = _listbox_directories + 1
		      populate_listbox_with_folder_contents(f.item(i),0)
		    else
		      _listbox_totalcount = _listbox_totalcount + 1
		      if  left( f.item(i).Name,1) <> "." then
		        // checking the last 4 characters - if it matches, display the file
		        if right(f.item(i).Name,4) = ".mp4" or right(f.item(i).Name,4) = ".m4v" then
		          MainWindow.FileList_Listbox.addrow  ""
		          dim j as integer = MainWindow.FileList_Listbox.ListCount - 1
		          
		          // MainWindow.FileList_StaticText.Text = "Files: Found " + str(j + 1) + " taggable of " + str(_listbox_totalcount) + " found files (" + str(_listbox_directories) + " dirs)"
		          
		          MainWindow.FileList_Listbox.cell(j,0) = f.item(i).name
		          MainWindow.FileList_Listbox.cell(j,2) = f.item(i).AbsolutePath
		          
		          check_dictionary = check_for_movie_or_tvshow_format(f.item(i).name,f.Item(i).Parent.AbsolutePath)
		          
		          dim check_dictionary_tmp as new dictionary
		          check_dictionary_tmp = get_mp4_tags_from_file(f.item(i).name,f.Item(i).Parent.AbsolutePath,1)
		          dim keys() as Variant = check_dictionary_tmp.Keys
		          for each key as String in keys
		            if check_dictionary_tmp.HasKey(key) then
		              if not check_dictionary.HasKey(key) then
		                check_dictionary.value(key) = check_dictionary_tmp.value(key)
		              end if
		            end if
		          next
		          
		          if check_dictionary.HasKey("valid") then
		            if check_dictionary.value("type") = "M" then
		              MainWindow.FileList_Listbox.cell(j,1) = "Movie"
		            else
		              MainWindow.FileList_Listbox.cell(j,1) = "TV Show"
		            end if
		          else
		            MainWindow.FileList_Listbox.cell(j,1) = "?"
		            MainWindow.FileList_Listbox.CellTag(j,0) = "RED"
		          end if
		          
		          get_txtfile_contents_for_movie(f.item(i).Parent.AbsolutePath, f.item(i).name)
		          _dict_savedxml.value(".fullmeta-" + StrToHex(f.item(i).name)) = check_dictionary.ExportXMLString(false)
		          MainWindow.FileList_Listbox.cell(j,3) = f.item(i).Parent.AbsolutePath
		          
		          MainWindow.FileList_Listbox.refresh
		        end if
		      end if
		    end if
		  next
		  
		  MainWindow.FileList_Listbox.SortedColumn=0
		  MainWindow.FileList_Listbox.ColumnSortDirection(0)=1
		  MainWindow.FileList_Listbox.Sort
		  
		  MainWindow.FileList_Listbox.EnableD = true
		  MainWindow.FileList_ProgressWheel.Enabled = false
		  MainWindow.FileList_ProgressWheel.visible = false
		  
		End Sub
	#tag EndMethod

	#tag Method, Flags = &h0
		Sub populate_ratingsmisc_for_showormovie()
		  _d_ratings_misc_for_show.Clear
		  _d_ratings_misc_for_show.value("loaded") = 0
		  
		  dim appdataf as folderitem = GetFolderItem(SpecialFolder.ApplicationData.AbsolutePath + "Tago")
		  dim _seriesratingsmiscdatafile as folderitem
		  if MainWindow.TVSeriesId_TextField.text.Len > 0 then
		    _seriesratingsmiscdatafile = GetFolderItem(appdataf.AbsolutePath + "TVDB-" + StrToHex( MainWindow.TVSeriesId_TextField.text) )
		    // MsgBox("Checking " + _seriesratingsmiscdatafile.AbsolutePath)
		    if _seriesratingsmiscdatafile.Exists then
		      // read it in
		      _d_ratings_misc_for_show.Clear
		      dim loaded as boolean = _d_ratings_misc_for_show.LoadXML(_seriesratingsmiscdatafile)
		      if loaded then
		        _d_ratings_misc_for_show.value("loaded") = 1
		      end if
		    else
		      MsgBox("Cannot load... file does not exist!")
		    end if
		  else
		    if MainWindow.IMDB_TextField.text.Len > 0 then
		      // MsgBox("Checking " + _seriesratingsmiscdatafile.AbsolutePath)
		      if _seriesratingsmiscdatafile.Exists then
		        _seriesratingsmiscdatafile =  GetFolderItem(appdataf.AbsolutePath + "IMDB-" + StrToHex(MainWindow.IMDB_TextField.text) )
		        dim loaded as boolean = _d_ratings_misc_for_show.LoadXML(_seriesratingsmiscdatafile)
		        if loaded then
		          _d_ratings_misc_for_show.value("loaded") = 1
		        end if
		      end if
		    else
		      MsgBox("Cannot load... file does not exist!")
		    end if
		  end if
		  
		  if _d_ratings_misc_for_show.value("loaded") = 1 then
		    // MsgBox("Loading defaults for Ratings & Misc")
		    defaults_for_rating_misc_page_load()
		  end if
		  
		End Sub
	#tag EndMethod

	#tag Method, Flags = &h0
		Sub reset_all_fields_on_description(clear_fields_or_not as integer)
		  if clear_fields_or_not = 1 then MainWindow.desc_title_TextField.Text = ""
		  MainWindow.desc_title_StaticText.enabled = false
		  MainWindow.desc_title_TextField.enabled = false
		  
		  if clear_fields_or_not = 1 then MainWindow.desc_episodeTitle_TextField.Text = ""
		  MainWindow.desc_episodeTitle_StaticText.enabled = false
		  MainWindow.desc_episodeTitle_TextField.enabled = false
		  
		  if clear_fields_or_not = 1 then MainWindow.desc_movieYear_TextField.Text = ""
		  MainWindow.desc_movieYear_StaticText.enabled = false
		  MainWindow.desc_movieYear_TextField.enabled = false
		  
		  if clear_fields_or_not = 1 then MainWindow.desc_originalAirDate_TextField.Text = ""
		  MainWindow.desc_originalAirDate_StaticText.enabled = false
		  MainWindow.desc_originalAirDate_TextField.enabled = false
		  
		  if clear_fields_or_not = 1 then MainWindow.desc_seriesId_TextField.Text = ""
		  MainWindow.desc_seriesId_StaticText.enabled = false
		  MainWindow.desc_seriesId_TextField.enabled = false
		  
		  if clear_fields_or_not = 1 then MainWindow.desc_starRating_PopupMenu.ListIndex = -1
		  MainWindow.desc_starRating_StaticText.enabled = false
		  MainWindow.desc_starRating_PopupMenu.enabled = false
		  
		  if clear_fields_or_not = 1 then MainWindow.desc_episodeNumber_TextField.Text = ""
		  MainWindow.desc_episodeNumber_StaticText.enabled = false
		  MainWindow.desc_episodeNumber_TextField.enabled = false
		  
		  if clear_fields_or_not = 1 then MainWindow.desc_isEpisode_PopupMenu.ListIndex = -1
		  MainWindow.desc_episodic_StaticText.enabled = false
		  MainWindow.desc_isEpisode_PopupMenu.enabled = false
		  
		  if clear_fields_or_not = 1 then MainWindow.desc_vProgramGenre_TextField.Text = ""
		  MainWindow.desc_vProgramGenre_StaticText.enabled = false
		  MainWindow.desc_vProgramGenre_TextField.enabled = false
		  
		  if clear_fields_or_not = 1 then MainWindow.desc_vActor_TextField.Text = ""
		  MainWindow.desc_vActor_StaticText.enabled = false
		  MainWindow.desc_vActor_TextField.enabled = false
		  
		  if clear_fields_or_not = 1 then MainWindow.desc_vGuestStar_TextField.Text = ""
		  MainWindow.desc_vGuestStar_StaticText.enabled = false
		  MainWindow.desc_vGuestStar_TextField.enabled = false
		  
		  if clear_fields_or_not = 1 then MainWindow.desc_vDirector_TextField.Text = ""
		  MainWindow.desc_vDirector_StaticText.enabled = false
		  MainWindow.desc_vDirector_TextField.enabled = false
		  
		  if clear_fields_or_not = 1 then MainWindow.desc_vExecProducer_TextField.Text = ""
		  MainWindow.desc_vExecProducer_StaticText.enabled = false
		  MainWindow.desc_vExecProducer_TextField.enabled = false
		  
		  if clear_fields_or_not = 1 then MainWindow.desc_vProducer_TextField.Text = ""
		  MainWindow.desc_vProducer_StaticText.enabled = false
		  MainWindow.desc_vProducer_TextField.enabled = false
		  
		  if clear_fields_or_not = 1 then MainWindow.desc_vWriter_TextField.Text = ""
		  MainWindow.desc_vWriter_StaticText.enabled = false
		  MainWindow.desc_vWriter_TextField.enabled = false
		  
		  if clear_fields_or_not = 1 then MainWindow.desc_description_TextArea.Text = ""
		  MainWindow.desc_description_StaticText.enabled = false
		  MainWindow.desc_description_TextArea.enabled = false
		  
		  if clear_fields_or_not = 1 then
		    // reset_fileinfosr_checkboxes()
		    reset_ratingsmisc_ccradiobuttons()
		    reset_ratingsmisc_svldfv_checkboxes()
		    reset_ratingsmisc_tvrradiobuttons()
		    reset_ratingsmisc_mpaarradiobuttons()
		    reset_extras_checkboxes()
		  end if
		End Sub
	#tag EndMethod

	#tag Method, Flags = &h0
		Sub reset_all_fields_on_fileinformation(clear_fields_or_not as integer)
		  MainWindow.ActualFilenameLabel_StaticText.enabled = false
		  MainWindow.ActualFilename_StaticText.Enabled = false
		  if clear_fields_or_not = 1 then MainWindow.ActualFilename_StaticText.text = ""
		  
		  MainWindow.NewFilenameLabel_StaticText.enabled = false
		  MainWindow.NewFilename_StaticText.enabled = false
		  if clear_fields_or_not = 1 then MainWindow.NewFilename_StaticText.text = ""
		  
		  MainWindow.RenameFile_BevelButton.enabled = false
		  
		  MainWindow.ShowOrMovieName_StaticText.enabled = false
		  MainWindow.ShowOrMovieName_TextField.enabled = false
		  if clear_fields_or_not = 1 then MainWindow.ShowOrMovieName_TextField.text = ""
		  
		  MainWindow.ShowOrMovieName_change_PushButton.Enabled = false
		  MainWindow.episodeTitle_StaticText.enabled = false
		  MainWindow.episodeTitle_TextField.enabled = false
		  if clear_fields_or_not = 1 then MainWindow.episodeTitle_TextField.text = ""
		  
		  MainWindow.ShowOrMovieType_StaticText.enabled = false
		  MainWindow.ShowOrMovieType_PopupMenu.enabled = false
		  if clear_fields_or_not = 1 then MainWindow.ShowOrMovieType_PopupMenu.listindex = -1
		  
		  //MainWindow.MediaType_TextField.enabled = false
		  if clear_fields_or_not = 1 then MainWindow.MediaType_TextField.text = ""
		  
		  MainWindow.Season_StaticText.enabled = false
		  MainWindow.Season_PopupMenu.enabled = false
		  if clear_fields_or_not = 1 then MainWindow.Season_PopupMenu.listindex = -1
		  
		  MainWindow.EpisodeNumber_StaticText.enabled = false
		  MainWindow.EpisodeNumber_PopupMenu.enabled = false
		  if clear_fields_or_not = 1 then MainWindow.EpisodeNumber_PopupMenu.listindex = -1
		  
		  MainWindow.Year_StaticText.enabled = false
		  MainWindow.Year_TextField.enabled = false
		  if clear_fields_or_not = 1 then MainWindow.Year_TextField.text = ""
		  
		  MainWindow.TVSeriesId_StaticText.enabled = false
		  MainWindow.TVSeriesId_TextField.enabled = false
		  if clear_fields_or_not = 1 then MainWindow.TVSeriesId_TextField.text = ""
		  
		  MainWindow.possibleseriesids_StaticText.enabled = false
		  if clear_fields_or_not = 1 then MainWindow.possibleseriesids_StaticText.text = ""
		  
		  
		  MainWindow.IMDB_StaticText.enabled = false
		  MainWindow.IMDBtt_StaticText.enabled = false
		  MainWindow.IMDB_TextField.enabled = false
		  if clear_fields_or_not = 1 then MainWindow.IMDB_TextField.text = ""
		  
		  MainWindow.ScreenRating_GroupBox.enabled = false
		  if clear_fields_or_not = 1 then
		    MainWindow.sr_s_CheckBox.value = false
		    MainWindow.sr_l_CheckBox.value = false
		    MainWindow.sr_fv_CheckBox.value = false
		    MainWindow.sr_v_CheckBox.value = false
		    MainWindow.sr_d_CheckBox.value = false
		  end if
		  
		  MainWindow.TVRating_GroupBox.enabled = false
		  if clear_fields_or_not = 1 then
		    MainWindow.tvr_RadioButton(0).value = false
		    MainWindow.tvr_RadioButton(1).value = false
		    MainWindow.tvr_RadioButton(2).value = false
		    MainWindow.tvr_RadioButton(3).value = false
		    MainWindow.tvr_RadioButton(4).value = false
		    MainWindow.tvr_RadioButton(5).value = false
		    MainWindow.tvr_RadioButton(6).value = false
		    MainWindow.tvr_RadioButton(7).value = false
		  end if
		  
		  MainWindow.MPAARating_GroupBox.enabled = false
		  if clear_fields_or_not = 1 then
		    MainWindow.mpaar_RadioButton(0).value = false
		    MainWindow.mpaar_RadioButton(1).value = false
		    MainWindow.mpaar_RadioButton(2).value = false
		    MainWindow.mpaar_RadioButton(3).value = false
		    MainWindow.mpaar_RadioButton(4).value = false
		    MainWindow.mpaar_RadioButton(5).value = false
		    MainWindow.mpaar_RadioButton(6).value = false
		    MainWindow.mpaar_RadioButton(7).value = false
		  end if
		  
		  
		  
		  
		  if 0 = 1 then
		    MainWindow.TagWritingMethods_GroupBox.enabled = false
		    if clear_fields_or_not = 1 then
		      MainWindow.mp4tags_CheckBox.value = false
		      MainWindow.pyTivoFiles_CheckBox.value = false
		    end if
		    MainWindow.SaveFile_BevelButton.Enabled = false
		  end if
		  
		  MainWindow.SearchOnline_BevelButton.enabled = false
		  
		End Sub
	#tag EndMethod

	#tag Method, Flags = &h0
		Sub reset_all_fields_on_ratingsmisc(clear_fields_or_not as integer)
		  MainWindow.ColorCodesLabel_StaticText.Enabled = false
		  MainWindow.ratingsmisc_colorCode_RadioButton(0).Enabled = false
		  MainWindow.ratingsmisc_colorCode_RadioButton(1).Enabled = false
		  MainWindow.ratingsmisc_colorCode_RadioButton(2).Enabled = false
		  MainWindow.ratingsmisc_colorCode_RadioButton(3).Enabled = false
		  if clear_fields_or_not = 1 then
		    MainWindow.ratingsmisc_colorCode_RadioButton(0).value = false
		    MainWindow.ratingsmisc_colorCode_RadioButton(1).value = false
		    MainWindow.ratingsmisc_colorCode_RadioButton(2).value = false
		    MainWindow.ratingsmisc_colorCode_RadioButton(3).value = false
		  end if
		  
		  MainWindow.RatingsM_TVScreenRatings_StaticText.enabled = false
		  MainWindow.ratingsmisc_s_CheckBox.enabled = false
		  MainWindow.ratingsmisc_l_CheckBox.enabled = false
		  MainWindow.ratingsmisc_fv_CheckBox.enabled = false
		  MainWindow.ratingsmisc_v_CheckBox.enabled = false
		  MainWindow.ratingsmisc_d_CheckBox.enabled = false
		  if clear_fields_or_not = 1 then
		    MainWindow.ratingsmisc_s_CheckBox.value = false
		    MainWindow.ratingsmisc_l_CheckBox.value = false
		    MainWindow.ratingsmisc_fv_CheckBox.value = false
		    MainWindow.ratingsmisc_v_CheckBox.value = false
		    MainWindow.ratingsmisc_d_CheckBox.value = false
		  end if
		  
		  MainWindow.ratingsmisc_TVRating_GroupBox.enabled = false
		  if clear_fields_or_not = 1 then
		    MainWindow.ratingsmisc_tvr_RadioButton(0).value = false
		    MainWindow.ratingsmisc_tvr_RadioButton(1).value = false
		    MainWindow.ratingsmisc_tvr_RadioButton(2).value = false
		    MainWindow.ratingsmisc_tvr_RadioButton(3).value = false
		    MainWindow.ratingsmisc_tvr_RadioButton(4).value = false
		    MainWindow.ratingsmisc_tvr_RadioButton(5).value = false
		    MainWindow.ratingsmisc_tvr_RadioButton(6).value = false
		    MainWindow.ratingsmisc_tvr_RadioButton(7).value = false
		  end if
		  
		  MainWindow.ratingsmisc_MPAARating_GroupBox.enabled = false
		  if clear_fields_or_not = 1 then
		    MainWindow.ratingsmisc_mpaar_RadioButton(0).value = false
		    MainWindow.ratingsmisc_mpaar_RadioButton(1).value = false
		    MainWindow.ratingsmisc_mpaar_RadioButton(2).value = false
		    MainWindow.ratingsmisc_mpaar_RadioButton(3).value = false
		    MainWindow.ratingsmisc_mpaar_RadioButton(4).value = false
		    MainWindow.ratingsmisc_mpaar_RadioButton(5).value = false
		    MainWindow.ratingsmisc_mpaar_RadioButton(6).value = false
		    MainWindow.ratingsmisc_mpaar_RadioButton(7).value = false
		  end if
		  
		  MainWindow.OtherTagsLabel_StaticText.Enabled = false
		  MainWindow.ratingsmisc_cc_CheckBox.enabled = false
		  MainWindow.ratingsmisc_stereo_CheckBox.enabled = false
		  MainWindow.ratingsmisc_sap_CheckBox.enabled = false
		  MainWindow.ratingsmisc_sub_Checkbox.enabled = false
		  MainWindow.ratingsmisc_repeat_CheckBox.enabled = false
		  MainWindow.ratingsmisc_hd_Checkbox.enabled = false
		  MainWindow.ratingsmisc_letterbox_CheckBox.enabled = false
		  if clear_fields_or_not = 1 then
		    MainWindow.ratingsmisc_cc_CheckBox.value = false
		    MainWindow.ratingsmisc_stereo_CheckBox.value = false
		    MainWindow.ratingsmisc_sap_CheckBox.value = false
		    MainWindow.ratingsmisc_sub_Checkbox.value = false
		    MainWindow.ratingsmisc_repeat_CheckBox.value = false
		    MainWindow.ratingsmisc_hd_Checkbox.value = false
		    MainWindow.ratingsmisc_letterbox_CheckBox.value = false
		  end if
		  
		End Sub
	#tag EndMethod

	#tag Method, Flags = &h0
		Sub reset_extras_checkboxes()
		  MainWindow.ratingsmisc_cc_CheckBox.value = false
		  MainWindow.ratingsmisc_stereo_CheckBox.value= false
		  MainWindow.ratingsmisc_sub_Checkbox.value = false
		  MainWindow.ratingsmisc_sap_CheckBox.value = false
		  MainWindow.ratingsmisc_repeat_CheckBox.value = false
		  MainWindow.ratingsmisc_letterbox_CheckBox.value = false
		  MainWindow.ratingsmisc_hd_Checkbox.value= false
		  
		  
		  
		  
		End Sub
	#tag EndMethod

	#tag Method, Flags = &h0
		Sub reset_fileinfosr_checkboxes()
		  MainWindow.sr_s_CheckBox.value = false
		  MainWindow.sr_v_CheckBox.value = false
		  MainWindow.sr_l_CheckBox.value = false
		  MainWindow.sr_d_CheckBox.value = false
		  MainWindow.sr_fv_CheckBox.value = false
		  
		End Sub
	#tag EndMethod

	#tag Method, Flags = &h0
		Sub reset_ratingsmisc_ccradiobuttons()
		  dim index as integer
		  for index = 0 to 3
		    MainWindow.ratingsmisc_colorCode_RadioButton(index).value = false
		  next
		  
		End Sub
	#tag EndMethod

	#tag Method, Flags = &h0
		Sub reset_ratingsmisc_mpaarradiobuttons()
		  dim index as integer
		  for index = 0 to 6
		    MainWindow.ratingsmisc_mpaar_RadioButton(index).value = false
		  next
		  
		End Sub
	#tag EndMethod

	#tag Method, Flags = &h0
		Sub reset_ratingsmisc_sr_checkboxes()
		  MainWindow.ratingsmisc_s_CheckBox.value = false
		  MainWindow.ratingsmisc_v_CheckBox.value = false
		  MainWindow.ratingsmisc_l_CheckBox.value = false
		  MainWindow.ratingsmisc_d_CheckBox.value = false
		  MainWindow.ratingsmisc_fv_CheckBox.value = false
		  
		End Sub
	#tag EndMethod

	#tag Method, Flags = &h0
		Sub reset_ratingsmisc_svldfv_checkboxes()
		  MainWindow.ratingsmisc_s_CheckBox.value = false
		  MainWindow.ratingsmisc_v_CheckBox.value = false
		  MainWindow.ratingsmisc_l_CheckBox.value = false
		  MainWindow.ratingsmisc_d_CheckBox.value = false
		  MainWindow.ratingsmisc_fv_CheckBox.value = false
		  
		End Sub
	#tag EndMethod

	#tag Method, Flags = &h0
		Sub reset_ratingsmisc_tvrradiobuttons()
		  dim index as integer
		  for index = 0 to 7
		    MainWindow.ratingsmisc_tvr_RadioButton(index).value = false
		  next
		  
		End Sub
	#tag EndMethod

	#tag Method, Flags = &h0
		Function StrToHex(s as string) As string
		  dim temp, result as string
		  dim i, theLen as integer
		  
		  theLen = len(s)
		  for i = 1 to theLen
		    temp = hex(asc(mid(s,i,1)))
		    while (lenb(temp) < 2)
		      temp = "0" + temp
		    wend
		    result = result + temp
		  next
		  
		  return result
		  
		  // Exception err
		  // HandleMyError(err, CurrentMethodName)
		End Function
	#tag EndMethod

	#tag Method, Flags = &h0
		Function strToVerticalPicture(str as string, str_size as integer, optional fontName as string = "Helvetica", optional rotation as boolean = true, optional usemask as boolean = false) As picture
		  const Pi=3.14159265358979323846264338327950
		  dim win as new window
		  dim strshape as StringShape
		  dim p as picture
		  dim getFontNumber as integer
		  
		  dim width_strShape, height_strShape, height_lessAscent as double
		  
		  strshape = new StringShape
		  strshape.TextFont = fontName
		  strshape.TextSize = str_size
		  strshape.Bold = true
		  if rotation then strshape.Rotation = -90*(Pi/180)
		  strshape.text = str
		  Strshape.HorizontalAlignment = StringShape.Alignment.Center
		  Strshape.VerticalAlignment =  StringShape.Alignment.Center
		  
		  win.Graphics.TextSize = str_size
		  win.Graphics.TextFont = strshape.TextFont
		  
		  width_strShape = win.Graphics.StringWidth( strShape.text )
		  height_strShape = win.Graphics.StringHeight( strShape.text , 999 )
		  height_lessAscent = ceil( height_strShape - win.Graphics.TextAscent )
		  
		  if rotation then
		    p = NewPicture(  height_strshape, width_strshape, 24 )
		    p.Graphics.DrawObject ( strShape , height_strShape - height_lessAscent , width_strShape / 2  )
		    if usemask then
		      p.Mask.RGBSurface.FloodFill 0,0,RGB(255,255,255)
		      p.Mask.Graphics.DrawObject ( strShape , height_strShape - height_lessAscent , width_strShape / 2  )
		    end if
		    
		  else
		    p = NewPicture( width_strshape,  height_strshape, 24 )
		    p.Graphics.DrawObject ( strShape ,  width_strShape / 2, height_strShape - height_lessAscent )
		    if usemask then
		      p.Mask.RGBSurface.FloodFill 0,0,RGB(255,255,255)
		      p.Mask.Graphics.DrawObject ( strShape ,  width_strShape / 2, height_strShape - height_lessAscent )
		    end if
		  end if
		  
		  win=nil
		  strshape=nil
		  
		  return p
		  
		End Function
	#tag EndMethod

	#tag Method, Flags = &h0
		Function validate_newfilename_options() As dictionary
		  dim status as string = "1"
		  dim reason as string = ""
		  
		  dim _dict as new dictionary
		  
		  if MainWindow.ActualFilename_StaticText.text.len < 5 then
		    status = "-1"
		    reason = "Filename not correctly defined."
		  end if
		  
		  _dict.value("status") = status
		  _dict.value("reason") = reason
		  
		  return _dict
		End Function
	#tag EndMethod


	#tag Property, Flags = &h0
		themoviedb_apikey As String = "57983e31fb435df4df77afb854740ea9"
	#tag EndProperty

	#tag Property, Flags = &h0
		themoviedb_getinfo_uri As String = "http://api.themoviedb.org/2.1/Movie.getInfo/en/xml/"
	#tag EndProperty

	#tag Property, Flags = &h0
		themoviedb_lookupimdb_uri As String = "http://api.themoviedb.org/2.1/Movie.imdbLookup/en/xml/"
	#tag EndProperty

	#tag Property, Flags = &h0
		themoviedb_lookupsearch_uri As String = "http://api.themoviedb.org/2.1/Movie.search/en/xml/"
	#tag EndProperty

	#tag Property, Flags = &h0
		thetvdb_apikey As String = "01D7C3B81B7DADE8"
	#tag EndProperty

	#tag Property, Flags = &h0
		thetvdb_getepisodeinfo As String = "http://thetvdb.com/api/"
	#tag EndProperty

	#tag Property, Flags = &h0
		thetvdb_search As String = "http://thetvdb.com/api/GetSeries.php?seriesname="
	#tag EndProperty

	#tag Property, Flags = &h0
		use_curl As Integer = 0
	#tag EndProperty

	#tag Property, Flags = &h0
		_already_said_okay As Integer = 0
	#tag EndProperty

	#tag Property, Flags = &h0
		_application_location As FolderItem
	#tag EndProperty

	#tag Property, Flags = &h0
		_atomic_parsley_location As string
	#tag EndProperty

	#tag Property, Flags = &h0
		_dict_exact_series_name_to_seriesid As dictionary
	#tag EndProperty

	#tag Property, Flags = &h0
		_dict_imdb_overview As dictionary
	#tag EndProperty

	#tag Property, Flags = &h0
		_dict_savedxml As dictionary
	#tag EndProperty

	#tag Property, Flags = &h0
		_dict_seriesid_files As dictionary
	#tag EndProperty

	#tag Property, Flags = &h0
		_dict_series_names_search As dictionary
	#tag EndProperty

	#tag Property, Flags = &h0
		_dict_showingBits As dictionary
	#tag EndProperty

	#tag Property, Flags = &h0
		_d_prefs As dictionary
	#tag EndProperty

	#tag Property, Flags = &h0
		_d_ratings_misc_for_show As dictionary
	#tag EndProperty

	#tag Property, Flags = &h0
		_enable_rdns As Integer = 0
	#tag EndProperty

	#tag Property, Flags = &h0
		_filesize As Integer = 0
	#tag EndProperty

	#tag Property, Flags = &h0
		_found_series_name As string
	#tag EndProperty

	#tag Property, Flags = &h0
		_found_series_overview As String
	#tag EndProperty

	#tag Property, Flags = &h0
		_ListBoxHighlightColor As Color = &cEDF3FE
	#tag EndProperty

	#tag Property, Flags = &h0
		_listbox_directories As Integer = 0
	#tag EndProperty

	#tag Property, Flags = &h0
		_listbox_totalcount As Integer = 0
	#tag EndProperty

	#tag Property, Flags = &h0
		_prefsdatafile As FolderItem
	#tag EndProperty


	#tag Constant, Name = kEscapedQuote, Type = String, Dynamic = False, Default = \"\\\\\"", Scope = Public
	#tag EndConstant

	#tag Constant, Name = kQuote, Type = String, Dynamic = False, Default = \"\"", Scope = Public
	#tag EndConstant


	#tag ViewBehavior
		#tag ViewProperty
			Name="Index"
			Visible=true
			Group="ID"
			InitialValue="-2147483648"
			InheritedFrom="Object"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Left"
			Visible=true
			Group="Position"
			InitialValue="0"
			InheritedFrom="Object"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Name"
			Visible=true
			Group="ID"
			InheritedFrom="Object"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Super"
			Visible=true
			Group="ID"
			InheritedFrom="Object"
		#tag EndViewProperty
		#tag ViewProperty
			Name="themoviedb_apikey"
			Group="Behavior"
			InitialValue="57983e31fb435df4df77afb854740ea9"
			Type="String"
			EditorType="MultiLineEditor"
		#tag EndViewProperty
		#tag ViewProperty
			Name="themoviedb_getinfo_uri"
			Group="Behavior"
			InitialValue="http://api.themoviedb.org/2.1/Movie.getInfo/en/xml/"
			Type="String"
			EditorType="MultiLineEditor"
		#tag EndViewProperty
		#tag ViewProperty
			Name="themoviedb_lookupimdb_uri"
			Group="Behavior"
			InitialValue="http://api.themoviedb.org/2.1/Movie.imdbLookup/en/xml/"
			Type="String"
			EditorType="MultiLineEditor"
		#tag EndViewProperty
		#tag ViewProperty
			Name="themoviedb_lookupsearch_uri"
			Group="Behavior"
			InitialValue="http://api.themoviedb.org/2.1/Movie.search/en/xml/"
			Type="String"
			EditorType="MultiLineEditor"
		#tag EndViewProperty
		#tag ViewProperty
			Name="thetvdb_apikey"
			Group="Behavior"
			InitialValue="01D7C3B81B7DADE8"
			Type="String"
			EditorType="MultiLineEditor"
		#tag EndViewProperty
		#tag ViewProperty
			Name="thetvdb_getepisodeinfo"
			Group="Behavior"
			InitialValue="http://thetvdb.com/api/"
			Type="String"
			EditorType="MultiLineEditor"
		#tag EndViewProperty
		#tag ViewProperty
			Name="thetvdb_search"
			Group="Behavior"
			InitialValue="http://thetvdb.com/api/GetSeries.php?seriesname="
			Type="String"
			EditorType="MultiLineEditor"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Top"
			Visible=true
			Group="Position"
			InitialValue="0"
			InheritedFrom="Object"
		#tag EndViewProperty
		#tag ViewProperty
			Name="use_curl"
			Group="Behavior"
			InitialValue="0"
			Type="Integer"
		#tag EndViewProperty
		#tag ViewProperty
			Name="_already_said_okay"
			Group="Behavior"
			InitialValue="0"
			Type="Integer"
		#tag EndViewProperty
		#tag ViewProperty
			Name="_atomic_parsley_location"
			Group="Behavior"
			Type="string"
			EditorType="MultiLineEditor"
		#tag EndViewProperty
		#tag ViewProperty
			Name="_enable_rdns"
			Group="Behavior"
			InitialValue="0"
			Type="Integer"
		#tag EndViewProperty
		#tag ViewProperty
			Name="_filesize"
			Group="Behavior"
			InitialValue="0"
			Type="Integer"
		#tag EndViewProperty
		#tag ViewProperty
			Name="_found_series_name"
			Group="Behavior"
			Type="string"
			EditorType="MultiLineEditor"
		#tag EndViewProperty
		#tag ViewProperty
			Name="_found_series_overview"
			Group="Behavior"
			Type="String"
			EditorType="MultiLineEditor"
		#tag EndViewProperty
		#tag ViewProperty
			Name="_ListBoxHighlightColor"
			Group="Behavior"
			InitialValue="&cEDF3FE"
			Type="Color"
		#tag EndViewProperty
		#tag ViewProperty
			Name="_listbox_directories"
			Group="Behavior"
			InitialValue="0"
			Type="Integer"
		#tag EndViewProperty
		#tag ViewProperty
			Name="_listbox_totalcount"
			Group="Behavior"
			InitialValue="0"
			Type="Integer"
		#tag EndViewProperty
	#tag EndViewBehavior
End Module
#tag EndModule
